Hi, I wrote a litte encryption algorithm for savegames.
Background: Until now I always stored savegames in plain text. Which didn't really matter because I haven't published anything yet. But as always, I'm working on a game and in the case I get to the point of a release I want at least some sort of encryption that prevents change of the player's stats or unlocking of achievements.
I searched for some simple encryption algorithms in lua but I could only find two or so, which were pretty messy, and I don't like to use code I don't understand. So I started writing my own little functions and until now they seem to work nicely.
What type of encryption is used:
I started with the simplest form of encryption: rotation. Because that's very easy to hack I added the feature to change the rotation interval with each character.
With ROT1, the encryption would look like this:
hello -> ifmmp
With my encryption, there is an array of rotation-values.
for example {1,2,3}
hello -> igomq
For my understanding, this is still easy to hack for a real hacker, but it's already MUCH better than simple rotation, and people won't be able to simply go into document folder and change values. You can use intervals between 0 and 255 and the chain can be as long as you like.
Miscellaneous:
I tried to comment the code in much detail.
You can store json strings.
If you like you can use the code freely.
Please let me know what you think. Criticism and improvement suggestions are very welcome, as I want to have a decent encryption for my savegames.
Greetings
zip
zip
Comments
local mydata = {}
mydata.somestring = "mystring"
mydata.somevalue = 42
//save
dataSaver.save("|D|mydata", encrypt(json.encode(mydata)))
print(mydata.somestring)
print(mydata.somevalue)
//load
local mydata = json.decode(decrypt(dataSaver.load("|D|mydata")))
print(mydata.somestring)
print(mydata.somevalue)
Likes: GiderosFan, pie, Astirian
Likes: Holonist, Astirian, Apollo14