So I recently made a fun little game of blackjack using java and swing and all that. I have the option to save the game data (user's name and bankroll), which simply writes the two into a text file in a specified folder. This then allows me to pull the two out of the text file, whenever the user wishes to open a saved game.
Now the problem with this, is that you can easily go into the text file and change everything (including how much money you have). This way, the next time the player loads the game, he has whatever amount of money he wrote in. I'd like to get rid of this problem in some way.
I was thinking about jumbling the words and numbers in the string around. But I know that it can't really be random, cause then I wouldn't be able to unjumble them later on when reading the text file to open a saved game.
So I'm looking fro some ideas, be it pseudocode or full code, on a way that I can save the game onto a text file in a way that I can then unjumble (unencrypt) later on
Related posts:








2 responses so far ↓
1 mapaghimagsik // Apr 14, 2008
True encryption can be a pain, since the key is stored somewhere. The question to ask yourself is how difficult do you want it to be to hack the game?
For something as simple as a game, you might just 64bit encode the file. Its very hackable, but this is just a blackjack game
For real encryption, java has powerful functions which allow for the generations of keys, and encryption of data
2 blessed_thang // Apr 14, 2008
Save it as a byte stream instead of a text file.
Most people don't now what an 8-byte character is should they manage to even look at the data on screen.
It's pretty much up to you, the programmer, how the data is stored and then retrieved to human readable form.
You can think of the 8-byte as a char. You could token your data's line into words, add a special char for psuedo lines and another special char for psuedo white space.
Then you write the data to file as a single column of words using [word+psuedoSpace+'\r'] and the last word of the original line gets psuedoReturn.
To make your program platform neutral you use:
String lineRET = System.getProperty( "line.separator")
// that way, if the file comes from Linux, Mac or Window, the proper character is inserted or read correctly.
The Crytography API is illegal to use outside the territorial boundaries of the United States. I don't know why, but that is the case. There are many games online, including PigLatin that are okay to use for all programming situations.
So, you would have to know all this anyway, before you consider scrambling. And, there's nothing hard about it. It's just humans are more comfortable writing / reading text files.
Leave a Comment