01-09-2006, 10:22 PM
I can't figure this out. I'm trying to make a very simple Encryption/decryption console app.
The first error is on the OPEN Filename FOR BINARY AS #F. It says there's a type mismatch at parameter 1.
Now, I'm not sure why. I assume parameter 1 is Filename. And I've dimensioned that as a STRING already. Why the type mismatch?
Now, I replace that with hard text, like "c:\foo.txt" and that solves that error...for some reason. Then there's another. On the "IF KeyString="" THEN..." part, it lists another type mismatch. "Type mismatch, found THEN". I can't seem to work around that one.
Any ideas folks?
The first error is on the OPEN Filename FOR BINARY AS #F. It says there's a type mismatch at parameter 1.
Now, I'm not sure why. I assume parameter 1 is Filename. And I've dimensioned that as a STRING already. Why the type mismatch?
Now, I replace that with hard text, like "c:\foo.txt" and that solves that error...for some reason. Then there's another. On the "IF KeyString="" THEN..." part, it lists another type mismatch. "Type mismatch, found THEN". I can't seem to work around that one.
Any ideas folks?
Code:
OPTION EXPLICIT
DIM Filename,KeyString,RealText,CipherText AS STRING
DIM F,FilePos,I,I2 AS INTEGER
DIM TempChar AS BYTE
GetFilename:
INPUT "Filename:";Filename
F=FREEFILE
OPEN Filename FOR BINARY AS #F
IF ERR=2 THEN
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 "Ciphering...";
WHILE NOT EOF(F)
GET #F,,TempChar
RealText=RealText + CHR$(TempChar)
WEND
TempChar=ASC(RealText)
FOR I=1 TO LEN(RealText)
FOR I2=1 TO LEN(KeyString)
TempChar=TempChar XOR ASC(MID$(KeyString,I2,1))
CipherText=CipherText + CHR$(TempChar)
NEXT
NEXT
FilePos=1
PUT #F,1,CipherText
CLOSE
PRINT "done."
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.