01-09-2006, 11:41 PM
Thanks, man! I didn't know that. I kneaded out a few other problems on my own.
Here's the finished code:
It's basically simple. You input a file, and a key string. The program XORs each character in the file with each character in the key string, and saves it in that same file. To decrypt, simply enter the same file and original key.
Not a very strong encryption, but alright if you want to stop your little brother from changing your settings in photoshop. :wink:
There is one thing more. Why doesn't the ERR handling thing work? If I enter a wrong filename, it doesn't tell me so, as it should.
Here's the finished code:
Code:
OPTION EXPLICIT
DIM AS STRING Filename,KeyString,RealText,CipherText
DIM AS INTEGER F,FilePos,I,I2
DIM TempChar AS BYTE
GetFilename:
INPUT "Filename: ",Filename
F=FREEFILE
OPEN Filename FOR BINARY AS #F
IF ERR THEN=2
PRINT "File not found!"
GOSUB GetFileName
ELSEIF ERR=3 THEN
PRINT "General File I/O error!"
PRINT "Press any key..."
SLEEP
END
END IF
GetKeyString:
INPUT "Key string: ",KeyString
IF KeyString="" THEN
PRINT "Empty Key String!"
GOSUB GetKeyString
END IF
PRINT "[De]ciphering...";
WHILE NOT EOF(F)
GET #F,,TempChar
RealText=RealText + CHR$(TempChar)
WEND
FOR I=1 TO LEN(RealText)
TempChar=ASC(MID$(RealText,I,1))
FOR I2=1 TO LEN(KeyString)
TempChar=TempChar XOR ASC(MID$(KeyString,I2,1))
NEXT
CipherText=CipherText + CHR$(TempChar)
NEXT
FilePos=1
PUT #F,1,CipherText
CLOSE
PRINT "done."
SLEEP
Not a very strong encryption, but alright if you want to stop your little brother from changing your settings in photoshop. :wink:
There is one thing more. Why doesn't the ERR handling thing work? If I enter a wrong filename, it doesn't tell me so, as it should.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
--------------------------------------
Freebasic is like QB, except it doesn't suck.