Some of the responses so far are making things harder than they need to be. You don't need to use encryption. Just add a secure checksum. Something like this:
import hashlib salt = "salt used by the whole game" playersalt = "salt specific to this player (optional)" def checksum(obj): return hashlib.sha224(str((salt, playersalt, obj))).hexdigest() Now your save and load routines would look something like this: def savegame(): state = score, numBullets, numLives csum = checksum(state) pickle.dump((state, csum), savefile) def loadgame(): state, csum = pickle.load(savefile) assert csum == checksum(state) score, numBullets, numLives = state The playersalt is only necessary if you don't want saved games from one player to work for a different player. And of course this assumes you don't release the source code. If you release the code, there's really no way to prevent players from generating any saved game they want. -Christopher On Mon, Nov 14, 2011 at 7:43 AM, Sam Bull <sam.hack...@sent.com> wrote: > I was just wondering what would be the best way to create a game's save > file. I can save the details in a text file without a problem, but I was > wondering how you would create the save file in a slightly more > protected manner. If it is to be a commercial game with trophies and > things then it would be too easy for the player to open the save file in > a text editor and change their level or max out their stats etc. > I was just wondering if anybody had a better method of saving, does > anybody know how the commercial PC games manage this? > > -- > Sam Bull <sambull.org> > PGP: 9626CE2B > >