Save RC4 Encryption Load RC4 Decrypt

BlitzMax Forums/BlitzMax Programming/Save RC4 Encryption Load RC4 Decrypt

BLaBZ(Posted 2013) [#1]
Hi All -

I'm using the RC4 Encryption in the following link

http://www.blitzbasic.com/codearcs/codearcs.php?code=1711

I'm unable to load and decrypt was I've previously encrypted, could someone help me figure out the following code? It has something to do with the contents of game.txt

game.txt


blitzcode.bmx
[codebox]
Strict

Local key:String = "09832hvb3@#)Fccenw238hr#@NO#@N#@dq"

Local file:TStream = ReadFile("game.txt")

Local data:String
While Not Eof(file)
data:+ReadLine(file) + "~n"
Wend

CloseStream(file)

Print data

Local encrypted:String = RC4(data,key)
Print encrypted

file = WriteFile("test.txt")
WriteLine(file,encrypted)
CloseStream(file)

file = ReadFile("test.txt")
Local data2:String
Local count:Int


BLaBZ(Posted 2013) [#2]
Ran out of room...

blitzcode.bmx



Henri(Posted 2013) [#3]
Hello,

if you replace
file = ReadFile("test.txt")
Local data2:String
Local count:Int
While Not Eof(file)
	data2:+ReadLine(file) + "~n"
	count:+1
Wend

...with this
file = ReadFile("test.txt")

Local count:Int
Local data2:String = LoadText(file)


...it seems to work.


-Henri


BLaBZ(Posted 2013) [#4]
Thanks! Perfect


BLaBZ(Posted 2013) [#5]
What's the difference between LoadText and LoadString functions?


Henri(Posted 2013) [#6]
LoadText() is a little more complicated function and takes into account the UTF-format that the file was saved. LoadString() is basically same as LoadByteArray() then return string from loaded byte array (turn bytes into characters).
So LoadString() is faster, but LoadText() involve more checking. Both might work.


-Henri