Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Here's another....file I/O difficulties.
#23
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.
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
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.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply


Messages In This Thread
Here's another....file I/O difficulties. - by Anonymous - 01-10-2006, 01:26 PM
Here's another....file I/O difficulties. - by Zack - 01-10-2006, 09:20 PM
Here's another....file I/O difficulties. - by DrV - 01-16-2006, 03:08 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)