'===========================================================================
' Subject: ENCRYPT YOUR BASIC PROGRAMS        Date: 05-03-97 (17:48)       
'  Author: Mark Otter                         Code: QB, QBasic, PDS        
'  Origin: loutre@xs4all.nl                 Packet: BINARY.ABC
'===========================================================================
DECLARE FUNCTION EnCrypt$ (Txt$)
'Hello everybody,
'This program wrote I some days ago because I like to do what this can do
'This program reads your .BAS file (saved as text for QB 4.x) and writes it
'to another text file (also .BAS) but al the strings between "" are coded,
'this means (for QB 4.x owners also after compiling), it is hard to much
'harder to cheat your program!
'Thanks are always welcome!! (Mark Otter(14) : loutre@xs4all.nl)
'Please put some were my name in your program, Small letters are allowed :-)
'This is Public Domain
'
'See ya!
'
'PS I did not do much syntax cheking (or how do you call it)
'PS.PS. When you have made this program better than i did, please send it to
'       me and the ABC Reader?!
'
'Now you may try it it
CLS
InFile$ = "SONGS.BAS"    'File to read (BAS Text file)
OutFile$ = "CODEOUT.BAS"  'File to write to (Also BAS Text file)

OPEN InFile$ FOR INPUT AS #1              'Open Infile
PRINT "Initializing " + InFile$ + "..."   'Search for function CHW$ and hope not been found
DO WHILE (NOT (EOF(1)))
   LINE INPUT #1, A$
   A$ = UCASE$(LTRIM$(RTRIM$(A$)))
   IF LEFT$(A$, 21) = "FUNCTION CHW$ (FAST$)" THEN
	  PRINT "ERROR: FUNCTION CHW$ (Fast$) does already exist!"
	  BEEP
	  END
   END IF
LOOP
CLOSE #1
'Code all the strings
PRINT "Coding " + InFile$ + " to " + OutFile$ + "..."
OPEN InFile$ FOR INPUT AS #1
OPEN OutFile$ FOR OUTPUT AS #2
DO WHILE (NOT (EOF(1)))
   LINE INPUT #1, A$
   A$ = LTRIM$(RTRIM$(A$))
   IF A$ <> "" THEN
	  IF INSTR(A$, CHR$(34)) = 0 THEN
		 PRINT #2, A$
	  ELSE
		 InString% = 0
		 OutBuffer$ = ""
		 FOR Q% = 1 TO LEN(A$)
			 T$ = MID$(A$, Q%, 1)
			 IF T$ <> CHR$(34) THEN
				IF InString% = 0 THEN
				   OutBuffer$ = OutBuffer$ + T$
				ELSE
				   C$ = EnCrypt$(T$)
				   IF ASC(C$) > 31 THEN
					  OutBuffer$ = OutBuffer$ + C$
				   ELSE
					  Number$ = LTRIM$(STR$(ASC(C$)))
					  OutBuffer$ = OutBuffer$ + CHR$(34) + "+CHR$(" + Number$ + ")+" + CHR$(34)
				   END IF
				END IF
			 ELSE
				IF InString% = 0 THEN
				   OutBuffer$ = OutBuffer$ + "CHW$( " + CHR$(34)
				   InString% = 1
				ELSE
				   OutBuffer$ = OutBuffer$ + CHR$(34) + ") "
				   IF InString% = 1 THEN InString% = 0
				END IF
			 END IF
		 NEXT Q%
		 PRINT #2, OutBuffer$
	  END IF
   END IF
LOOP
CLOSE #1
PRINT #2, "    "
PRINT #2, "defint a-z"
PRINT #2, "function chw$(fast$)"
PRINT #2, "cpuspeed$=" + CHR$(34) + CHR$(34)
PRINT #2, "for music=1 to len(fast$)"
PRINT #2, "bios=asc(mid$(fast$,music,1))"
PRINT #2, "harddisk=255-bios"
PRINT #2, "cpuspeed$=cpuspeed$+chr$(harddisk)"
PRINT #2, "next music"
PRINT #2, "chw$=cpuspeed$"
PRINT #2, "end function"
CLOSE #2
PRINT "Done" 'We're done.

FUNCTION EnCrypt$ (Txt$)
EnCrypt$ = CHR$(255 - ASC(Txt$))
'This is a simple way to code a character and it's easy to crack in a binary
'file but in an executable-file this is very difficult (I Think)
END FUNCTION
