Sign in to follow this  

need help with binary file i/o

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am doing high scores for a game. I was wondering if it's possible in binary file i/o to write bit by bit and to read bit by bit. I don't want to use characters because when a binary file with characters is opened as a text file the characters will show up as text. I would like to form a code for storing the information so it can't be read and tampered with by the user of the game.

Share this post


Link to post
Share on other sites
Well, a few answers here:

1. "binary file I/O" is not a code. For numbers, it tends to mean that you give their direct machine representation, instead of a string representing that number. For strings, it's exactly the same. Opening a file "in binary mode" simply means that the byte stream is not tampered with in order to convert line endings.

2. If you want to use some form of code to prevent tampering, I'd suggest a simple XOR. XOR each byte with some value when saving it, then XOR with the same value when reading it back. This form of encryption is easily hackable by anyone with knowledge of programming who really wants to, but any form of encryption will be insecure if your program contains the means to encode it. That's simple computer science.

3. Virtually no professional-quality games make any attempt to "hide" game data and resources from users. There simply isn't any need to. If someone wants to hack into the game and change all the imps into toaster ovens, why stop them? If someone wants to pretend they got ten billion kajillon points and impress all their friends, let 'em. It's really not your place as a programmer to dictate how they will use the game, just what features are available.

Share this post


Link to post
Share on other sites
Well, what I do to make things simpler is to keep everything in text mode, but I encrypt my stuff with a simple XOR that will keep meddlesome non-hackers out of my stuff, plus a check sum to maintain integrity. You should go down that route, too.

Share this post


Link to post
Share on other sites

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this