View Full Version : Simple encryption?
super_e
08-24-2004, 01:51 AM
Hi Guys,
I would like to hide my game's file contents (INI file, dat files, etc.) and show garbage characters when opened in notepad so that the average user cannot edit it, does this mean I have to encrypt them?
Anyone has some simple encryption code to share? :)
Thanks!
MiCo Games
08-24-2004, 02:01 AM
You could simply pick a value between 0 and 255. Add this to each character in the file to encrypt it, subtract it from each character to decrypt... Simple, but not all that safe...
You could simply pick a value between 0 and 255. Add this to each character in the file to encrypt it, subtract it from each character to decrypt... Simple, but not all that safe...
Nah... not add. You've to xor it.
encrypt:
byte crypt=o_byte^key_byte;
decrypt:
byte decrypt=c_byte^key_byte;
However, I wouldn't bother doing stuff like that. Use some kind of pak format, because it makes life easier... the "security" you get there is about the same.
Phil Newton
08-24-2004, 02:46 AM
I used to use an XOR on each byte. You can make it more secure by picking a random number for each byte. I can go into more detail if you wish :)
That should be secure enough for most people, and will at least stop people poking around and changing values.
MiCo Games
08-24-2004, 02:50 AM
Nah... not add. You've to xor it.
I can assure you, it works just as well if you add :) just make sure that it wraps properly (will do if you use an unsigned char for the calculation).
I agree that it is not necessary though... Why would you not want people to be able to edit the files?
ggambett
08-24-2004, 05:40 AM
1) Add and XOR effectively work and have similar results.
2) XORing or adding to a string of zeros will give you the value. Beware. Probably not a problem with ASCII files
3) Use a "key" to XOR or to add instead of just a value. Pseudocode example :
sKey = "thisismykey"
for i = 0 to len(sData):
sData[ i ] = sData[ i ] XOR sKey[ i % len(sKey) ]
Again, beware of encrypting a string of zeros, you will give away the key.
4) To solve the "encoding zeros" problem, add the position i to the key (or better yet, some f(i)).
sData[i] = sData[i] XOR (sKey[i % len(sKey)] + i)
Note that this is trivial encryption as you requested, and therefore trivial to crack too.
Jeff Evertt
08-24-2004, 09:24 AM
You might just compress before saving and and uncompress on load, using zlib. Not encrypted, but your casual user wont be able to mess with it.
-Jeff
www.evertt.com (http://www.evertt.com)
super_e
08-25-2004, 01:58 AM
Thanks for the tip guys! I just opted for a simple XOR encryption since I just need a simple INI file to be encrypted. Compression maybe great but I felt that its too much for my needs. :) Just in case some of you may need some sample code, the link below has been very helpful for me.
http://download.cdsoft.co.uk/tutorials/xorencryption/
Powered by vBulletin™ Version 4.1.3 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.