Wrote a snake game that saves the highscore to a txt file. anyone can change that.. well, not anymore. before it writes the highscore to the save file it runs it thru an algorithm and stores a security number with it. when highscore info is loaded it runs the highscore from the file thru the algorithm and checks it againts the number that was stored with it when saved. to change the highscore in the file you also have to change the security number
2/16/2017 6:54:15 PMLordHill
3 AnswersNew Answer
I know, you probably don't care, but since my wife and kids don't care either, I like telling people when I do things.
So, in other words, you created a cryptographic hash function. Sounds good, but it is sufficiently randomized? I'll use the classic "Alice and Bob" for this scenario. Let's say Alice and Bob are two people who download your snake game. Alice and Bob both play the game, and they get the same high score. Is the hash (the security number) the same for the both of them? If so, then you still have a problem, because if Alice gets a higher score than Bob, Bob could get both the score and the hash, put them into his own text file, and start up the program again with Alice's high score. Yeah, cryptography is tough like that. You could get around it by creating a text file somewhere else on the user's computer, putting a random number in it, and using the hash function with that number as a key.
I have actually been thinking about this for a while. when writing it this morning I decided it is just Snake and if they want to put that much effort into it then so be it, but I have been thinking about it since. I have been considering a small rewrite tying in the highscore name so if the score and name run thru the algorithm combined don't result in the same security code then it wouldn't work.. if nothing else, using your example.. Bob could only have alices highscore if he also took Alice as the name on the highscore