DECLARE SUB AskTo () DECLARE SUB ErrMsg (code%, file$) DECLARE SUB GetInputs (file$, tkey$) DECLARE SUB GetCmdLine (file$, tkey$) DECLARE SUB DoEncrypt (file$, tkey$) 'ben's cool encryption program 'ENCRYPT.EXE '******************************************* 'variables tkey$ = "" 'encryption/decryption key temp$ = "" 'read from file into here file$ = "" 'file to encrypt/decrypt '******************************************* main: PRINT COLOR 9 PRINT "ENCRYPT.EXE, a cool program by Ben Weir" COLOR 7 GetCmdLine file$, tkey$ 'GetInputs file$, tkey$ DoEncrypt file$, tkey$ END DEFINT A-Z SUB AskTo LOCATE , 1 COLOR 4 PRINT "Do you really want to abort? "; COLOR 7 DO in$ = UCASE$(INKEY$) LOOP UNTIL in$ = "Y" OR in$ = "N" IF in$ = "Y" THEN ErrMsg 3, file$ LOCATE , 1 PRINT SPACE$(80); END SUB SUB DoEncrypt (file$, tkey$) filepos! = 0 OPEN file$ FOR BINARY AS #1 tkey = LEN(tkey$) TotalBytes! = LOF(1) IF TotalBytes! = 0 THEN ErrMsg 1, file$ temp$ = " " PRINT "Now encrypting: "; COLOR 2 PRINT file$ COLOR 7 PRINT "with this key: "; COLOR 2 PRINT tkey$ COLOR 7 t! = TIMER DO FOR x = 1 TO tkey filepos! = filepos! + 1 tkeyx$ = MID$(tkey$, x, 1) GET #1, filepos!, temp$ temp$ = CHR$(ASC(temp$) XOR ASC(tkeyx$)) PUT #1, filepos!, temp$ IF filepos! = TotalBytes! THEN EXIT FOR NEXT x LOCATE , 1 percent! = (filepos! / TotalBytes!) * 100 PRINT "percent finished:"; PRINT USING "###"; percent!; in$ = INKEY$ IF in$ = CHR$(27) THEN AskTo LOOP UNTIL filepos! = TotalBytes! CLOSE #1 TotalTime! = TIMER - t! IF TotalTime! = 0 THEN TotalTime! = .01 PRINT PRINT file$; " successfully encrypted in"; COLOR 2 PRINT USING "###.##"; TotalTime!; COLOR 7 PRINT " seconds,"; COLOR 2 PRINT USING "##.##"; (TotalBytes! / TotalTime!) / 1024; COLOR 7 PRINT " kb per second" END SUB DEFSNG A-Z SUB ErrMsg (code%, file$) SELECT CASE code% CASE 1: PRINT "File not found: "; file$ CLOSE #1 KILL file$ CASE 2: PRINT "Syntax:" PRINT " ENCRYPT.EXE " CASE 3: COLOR 4 PRINT "ENCRYPTION ABORTED!" END SELECT END END SUB DEFINT A-Z SUB GetCmdLine (file$, tkey$) lencom = LEN(COMMAND$) COMline$ = LTRIM$(RTRIM$(COMMAND$)) FOR x = 1 TO lencom temp$ = MID$(COMline$, x, 1) IF temp$ <> " " AND tkey = 0 THEN file$ = file$ + temp$ IF temp$ <> " " AND tkey = 1 THEN tkey$ = tkey$ + temp$ IF temp$ = " " THEN tkey = 1 NEXT x IF file$ = "" OR tkey$ = "" THEN ErrMsg 2, file$ END SUB DEFSNG A-Z SUB GetInputs (file$, tkey$) PRINT PRINT "what file to encrypt/decrypt: "; INPUT file$ PRINT PRINT "what is the key: "; INPUT tkey$ PRINT END SUB