01-10-2006, 09:20 PM
Back on the subject of Ethan Winer's clever little encryption there...
Well here it is in my expanded form. Shown is code for both ciphering and deciphering. It's a few lines longer, but a heckuva lot clearer.
PswdPos indicates which character in the password string is to be used for each iteration. It's incremented each time, and reset once it exceeds the length of the password.
Well here it is in my expanded form. Shown is code for both ciphering and deciphering. It's a few lines longer, but a heckuva lot clearer.
Code:
OPTION EXPLICIT
CONST Text="Move 32nd platoon SSW 10 miles"
CONST Password="armypassword"
DIM AS STRING DecipheredText,CipheredText
DIM TempChar AS BYTE,PswdPos AS INTEGER,I AS INTEGER
PswdPos=1
FOR I=1 TO LEN(Text)
IF PswdPos > LEN(Password) THEN PswdPos=1
TempChar=ASC(MID$(Text,I,1)) XOR ASC(MID$(Password,PswdPos,1))
CipheredText=CipheredText + CHR$(TempChar)
PswdPos=PswdPos + 1
NEXT
PRINT "Text: ";Text
PRINT "Password: ";Password
PRINT "Ciphered text: ";CipheredText
PswdPos=1
FOR I=1 TO LEN(CipheredText)
IF PswdPos > LEN(Password) THEN PswdPos=1
TempChar=ASC(MID$(CipheredText,I,1)) XOR ASC(MID$(Password,PswdPos,1))
DecipheredText=DecipheredText + CHR$(TempChar)
PswdPos=PswdPos + 1
NEXT
PRINT "Deciphered text: ";DecipheredText
SLEEP
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.