( ) - 5


};

// polynomial is

// X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0

unsigned crc32(unsigned crc, unsigned char *buf, unsigned buflen)

{

for(unsigned i = 0; i < buflen; i++)

crc = crc32tab[(unsigned char)(crc ^ unsigned(buf[i]))] ^ ((crc >> 8) & 0x00ffffff);

return crc;

}

/:

void encrypt(unsigned char * buf, unsigned buflen, unsigned char * gamma)

{

unsigned prev, next;

unsigned char * pgamma;

// 1

//

// 1 -

prev = 0xffffffff;

pgamma = gamma;

for(int i = 0; i < buflen; i++) {

next = crc32(prev, buf+i, 1);

next = crc32(next, pgamma+i, 1); //

buf[i] += prev;

prev = next;

}

// 2 -

prev = 0xffffffff;

pgamma = gamma+buflen;

for(int i = buflen-1; i >= 0; i--) {

next = crc32(prev, buf+i, 1);

next = crc32(next, pgamma+i, 1); //

buf[i] += prev;

prev = next;

}

// 2

//

// 3 -

prev = 0xffffffff;

pgamma = gamma+(buflen<<1);

for(int i = 0; i < buflen; i++) {

buf[i] += prev;

prev = crc32(prev, buf+i, 1);

prev = crc32(prev, pgamma+i, 1); //

}

// 4 -

prev = 0xffffffff;