This are the programs I wrote to test the checksum algorithm I created for XRally.

First of all... why a checksum algorithm? Simple! Imagine that you played a great game at the "Real Level", made a lot of points, and became the first one in the ranking. Cool, huh? Now imagine that someone changed the "Real Level", maybe just for fun, to see how it looks like to change a level, etc.

Then, let's imagine that they add a lot of flags, change the default amount of fuel, etc. Then, someone plays at this level and makes a lot of points, much more then you, and your record disappeared.

To avoid this problem, when the records are stored in file, a checksum number of the level data is stored with them, so that the records refer to this checksum, and not just for the level name.

But why create a checksum algorithm? There are a lot of them around there, like CRC and md5, that work pretty well. I know that. But I don't know how to implement them! :)

I've tried to read the rfc's, the algorithms descriptions, etc, but I not a computer scientist. I'm still at my first period of Engineering, and binary logic is something that I will only learn at my fifth or sixth period. So, I gathered what I understood of the CRC algorithm and created a new one.

Basically, the checksum starts at 0, and increases with each letter that the file has, depending of the value and position of the character. Take a look at the source code for details.
Also note that, in the game implementation, lines with comments are ignored, to avoid just a small change in the comments to change all the program.

Also note that this checksum thing I invented is not designed to avoid people from cheating. They still can modify the hiscore file by hand, as long as they have permission for that. I don't think that it makes sense to cryptograph the hiscore file. (first because I don't know how to do that. Second because I think is a bit too much to a game like XRally). The idea of it is to avoid that different levels have the same hiscore table, which I think is unfair.

The files in this directory:

oldbytesum.c  -> My first try with the checksum. The character position is
								 not taken into consideration
bytesum.c		  -> My second try. The character position is taken into consi
								 deration, but not too heavily. The simple exchanging of 
								 characters may still have the same checksum
newbytesum.c  -> My last and final try. It should work fine (see below)
minorchange.c -> A small program that change the value of a random charact
								 er to a random one in the range 32-127 (readable characters)
xchgchar.c		-> A small program that exchanges the position of two random 
								 characters
testsum.sh		-> A shell script to test the algorithm

The testsum script basicly runs the minorchange or xchgchar programs in a file and checks if the new checksum is different from the previous one. It doest that a lot of times! Take a look at it on how to customize.

My algorithm runned the xchgchar program about 3500 times before repeating the checksum, and the minorchange one around 6000 times. (This results depends on the random seed, so aren't very cientific. Besides, I didn't have the patience to repeat the same test a lot to do more statistics)

If you take a look at the sourcecode, you will see that this algorithm isn't very complex. In fact, the only thing it does is some multiplications, modulus and shifts of the characters value and position. It isn't very scientific, but it works! :)

If someone with a deep knowledge in cryptographic and binary logic cares to do somethin more elaborated (as long as I have a grasp of understanding it), just drop me a mail.
