Thread: When to encrypt?

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    When to encrypt?

    I have an .ini file for a text game I'm making. It holds the basic stuff, like the player's profile, and also, the different classes of characters. Such as, Orcs, Imperials, Imps, and their respective strength, dexterity, stamina values. Of course, I don't want the casual player to edit the .ini file with notepad. So I've decided to go with Caesar Encryption. I've got it all implemented. But I'm not sure when or where to call this encryption function. Do I read the whole file at runtime? But what about after runtime, the user can edit the .ini file. Note that I'm still editing values and stuff to tweak the gameplay. Is encryption a one time deal and it's encrypted forever? The file will be in the same folder of the .exe, and I just want to stop someone from double clicking on it, and seeing that it can be edited easily.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    60
    The only thing i can think of right now is to encrypt the whole file byte by byte so that the first bytes will also change, so that it won't be recognized by any program or editor. So user won't be able to change it..

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Caesar should be fine. Just read the whole file in at runtime, and then decrypt - just don't write the decrypted stuff to disk. (You're not... are you?)

    Alternatively, you could also consider using a binary data file. Numbers (like strength, dexterity, etc) would not be obvious to the novice user. Another solution would be to store the data in the executable itself, in an array perhaps. (IIRC, Nethack, (a game) does this, for instance.)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Actually, why not allow causal players to modify the data? Effectively they get to "godmode" or increase difficulty level in some specific area if they want, and this may make some of them happy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Honestly, I wouldn't be encrypting data in an INI file. From my experience with games, INI files contain information that's meant to be changed. Basic options, advanced options, system information, etc... Any kind of character data I would store in some other extension (just make one up) because people are going to see INI and think it's something they should be able to edit.

    As for the encryption method... it really doesn't matter in my opinion. People aren't going to bother trying to decrypt it to change some stats unless the game itself is impossible. I would go with the most efficient and least time consuming encryption possible. No point in using any more resources than necessary.
    Sent from my iPadŽ

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ok, I see. I won't encrypt the .ini and I'll take all the precious info I don't want changed out of there. But I still want to know how this encryption works. I understand my technique I want to use (Caesar), but I don't understand something. Do I encrypt the file when the game is all done and ready to be released? Where should I call functions to encrypt/decrypt the file? I'm confused...
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    On Save and Load, of course.
    Sent from my iPadŽ

  8. #8
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Okay, but when I'm ready to release the game, should this file be encrypted already so people can't edit it? Is the file encrypted all the time, regardless of whether it's running?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  9. #9
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    The file should always be encrypted. When you run your program the program should read in the file, decrypt what it needs (in memory of course). If you want to change some of its values during the game for whatever reason encrypt what is stored in memory and save that to your file.

  10. #10
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ok! Would it be wise to create a sort of encryption utility to easily encrypt files? Such as, ask for a parameter of the filename and it would encrypt. And then have the same function in the utility be used in the actual program as well as the decryption function. Would this be wise?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  11. #11
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Erm.

    What I'd do is just load the file (encrypted) to some kind of variable (string, vector or whatever). Use a function to decrypt it. Then get all the useful stuff you need from that, whatever that may be. At the end of the day you're never actually converting an encrypted file to a decrypted file.

    But there would be no harm in creating a function just to decrypt a specific file and save it to memory, but I would create a few functions: One for loading a file, one for encoding or decoding a string, one for saving a string, one for loading and decrypting (in one swoop, just for convenience), and one for encoding and saving (again in one swoop and for convenience).

    Note. If you're using a Cesar method of encryption you'll have to pass a cypher into it for it to be decoded. it's not really wise to hard code this into your program if you think people will try to hack it.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    630
    Just curious how do you read .ini file? Using boost::spirit ?

  13. #13
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I'm using some headers called IniFile.h and IniFile.cpp It isn't a library, just some helpful functions.
    Last edited by Sentral; 12-24-2006 at 11:57 AM.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to decrypt / encrypt using libgcrypt ? (ARC4)
    By jabka in forum C Programming
    Replies: 6
    Last Post: 04-21-2010, 11:34 PM
  2. Strange issue utilizing encrypt() in libcrypt
    By TheComedian in forum C Programming
    Replies: 8
    Last Post: 01-18-2009, 07:14 AM
  3. dll to encrypt packet sends
    By splintter in forum C++ Programming
    Replies: 22
    Last Post: 04-20-2008, 09:00 PM
  4. encrypt input message
    By axedia in forum C Programming
    Replies: 1
    Last Post: 05-30-2005, 12:48 AM
  5. Ask about Encrypt data 2 times.
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 07-16-2002, 03:28 AM