Simple encryption?

Discussion in 'Game Development (Technical)' started by super_e, Aug 24, 2004.

  1. super_e

    Original Member

    Joined:
    Aug 17, 2004
    Messages:
    34
    Likes Received:
    0
    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. MiCo Games

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    38
    Likes Received:
    0
    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. oNyx

    Original Member

    Joined:
    Jul 26, 2004
    Messages:
    1,212
    Likes Received:
    0
    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. Phil Newton

    Original Member

    Joined:
    Aug 4, 2004
    Messages:
    83
    Likes Received:
    0
    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. MiCo Games

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    38
    Likes Received:
    0
    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. ggambett

    Moderator Original Member Indie Author

    Joined:
    Jul 26, 2004
    Messages:
    1,982
    Likes Received:
    5
    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.
     
    #6 ggambett, Aug 24, 2004
    Last edited: Aug 24, 2004
  7. Jeff Evertt

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    28
    Likes Received:
    0
    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. super_e

    Original Member

    Joined:
    Aug 17, 2004
    Messages:
    34
    Likes Received:
    0
    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/
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer