Here's a quick example I just knocked together. It's still very simple, but a little harder to crack than just adding or subtracting 15 to the ASCII value.
I guess however that it's not really necessary to be crack-proof - just to stop Joe Bloggs from opening it up and changing anything.
What it does is add 15 to the value similar to the original idea, but also adds 1 to the first character, 2 to the second character, 3 to the third and so on. Not impossible, but a little harder to figure out...
Input "Enter a sentence: ";Sentence$
NewSentence$ = Encode(Sentence$)
If File Exist("Encoded.txt") Then Delete File "Encoded.txt"
Open To Write 1,"Encoded.txt"
Write String 1,NewSentence$
Close File 1
Print "Encrypted File Written. Press A Key To Load It Back In..."
Print
Wait Key
NewSentence$ = ""
Open To Read 1,"Encoded.txt"
Read String 1,NewSentence$
Close File 1
Print "Loaded: ";NewSentence$
Sentence$ = Decode(NewSentence$)
Print "Decoded: ";Sentence$
Print
Print "Any Key To End..."
Wait Key
End
Function Encode(CharString$)
NewSentence$ = ""
For N=1 To Len(CharString$)
CharASCIICode = ASC(Mid$(CharString$,N))
NewSentence$ = NewSentence$ + Chr$(CharASCIICode+15+N)
Next N
EndFunction NewSentence$
Function Decode(CharString$)
Sentence$ = ""
For N=1 To Len(CharString$)
CharASCIICode = ASC(Mid$(CharString$,N))
Sentence$ = Sentence$ + Chr$(CharASCIICode-15-N)
Next N
EndFunction Sentence$
Just call the Encode function in a loop with each piece of information you want to write,
inside the Open To Write/Close File block.
Call the Decode function in a loop with each piece of information you want to write,
inside the Open To Read/Close File block.
If all your data is of type
string then the functions will work with 'numbers' too - ie a hiscore table. (Numeric variables can be converted to strings with STR$).
TDK_Man