06-11-2003, 12:46 PM
Try this on for size. Remember you won't have access to the key, but you can access the file with the encrypted string in it.
Beat that!
Code:
' ** Encryption routine **
' By the oracle
' This is a function I made up a while ago when working with zack on a
' GUI login for QBasic. We never got around to finishing it...
' This program has a key, it is outputted to a file at the moment, but
' this could be changed in the future.
DECLARE SUB encrypt (encrypt$)
RANDOMIZE TIMER
CLS
PRINT "The oracle's encryption routine"
PRINT "This program will take a string that you input and encrypt it."
PRINT "The result is outputted to a file"
PRINT "F-keys etc will be trimmed from the string. Only valid characters, please!"
PRINT
INPUT "What is the string you want to encrypt? ", enc$
t# = TIMER
encrypt enc$
t# = TIMER - t#
PRINT "The string has been outputted to strng.txt."
PRINT "The encryption took "; t#; "seconds."
INPUT "Do you want to view the string? ", yn$
IF LCASE$(LEFT$(yn$, 1)) = "y" THEN
OPEN "strng.txt" FOR INPUT AS #1
INPUT #1, a$
PRINT a$
WHILE INKEY$ = "": WEND
CLOSE #1
END IF
END
SUB encrypt (enc$)
' DIM stuff
DIM rndlen AS INTEGER, ikey AS INTEGER, i AS INTEGER, handle AS INTEGER, keyhandle AS INTEGER
' Make a random key
rndlen = INT(RND * 500)
FOR i = 1 TO rndlen
key$ = key$ + CHR$(INT(RND * 95) + 32)
NEXT i
' Encrypt the inputted string based on the key.
key$ = "!"
FOR i = 1 TO LEN(enc$)
handle = ASC(MID$(enc$, i, 1)) ' I'm unfamiliar with PEEK
ikey = ikey + 1
IF ikey > LEN(key$) THEN ikey = 1
keyhandle = ASC(MID$(key$, ikey, 1))
temp& = INT(handle * keyhandle + 9999)
temp$ = LTRIM$(STR$(temp&))
FOR inc = LEN(temp$) TO 7
temp$ = "0" + temp$
NEXT inc
encryptedstring$ = encryptedstring$ + temp$
NEXT i
OPEN "strng.txt" FOR OUTPUT AS #1
PRINT #1, encryptedstring$
CLOSE
OPEN "key.txt" FOR OUTPUT AS #1
PRINT #1, key$
CLOSE
END SUB
Beat that!