/*
Speed Challenge network data checksum 0.1
by Luigi Auriemma
e-mail: aluigi@autistici.org
web: aluigi.org
Introduction
============
This algorithm is used to calculate the checksum of the network data
exchanged by the game Speed Challenge.
It is a big-endian 16 bits number located at the beginning of the data.
How to use
==========
I have modified the original algorithm for comodity so now you can
simply call the speed_challenge_net_cksum() function passing the data
and its size as arguments.
Example:
*(u_short *)buff = htons(speed_challenge_net_cksum(buff, len));
*/
unsigned short speed_challenge_net_cksum(unsigned char *data, int size) {
int rest;
unsigned short crc;
rest = size + 2;
crc = (rest >> 8) | (rest << 8);
*(unsigned short *)data = 0;
size >>= 1;
while(size--) {
crc += *(unsigned short *)data;
data += 2;
}
if(rest & 1) crc += *data;
crc ^= 0x7ed5;
return(crc);
}