+ Reply to Thread
Results 1 to 8 of 8

Thread: Simple encryption?

  1. #1

    Default Simple encryption?

    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!

  2. #2

    Default

    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...

  3. #3
    Senior Member
    Join Date
    Jul 2004
    Posts
    1,216

    Default

    Quote Originally Posted by MiCo Games
    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.

  4. #4
    Member
    Join Date
    Aug 2004
    Location
    Nottingham, UK
    Posts
    83

    Default

    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.

  5. #5

    Default

    Quote Originally Posted by oNyx
    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?

  6. #6
    Moderator
    Join Date
    Jul 2004
    Location
    Zürich, Switzerland
    Posts
    1,966

    Default

    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 :
    Code:
    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)).
    Code:
    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.
    Last edited by ggambett; 08-24-2004 at 05:42 AM.
    Gabriel Gambetta
    Google Zürich - Formerly Mystery Studio

  7. #7
    Junior Member
    Join Date
    Jul 2004
    Posts
    28

    Default

    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

  8. #8

    Smile

    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/

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts