c++ - CRC32 not calculated right -


i use simple algorithm calculate crc32 gives wrong values.

i compare output values calculator ones looks different

unsigned int crc32_tab[256] = {         0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,         0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,         0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,         0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,       .........,..............,.............,.........,...........     }; 

function use lookup table

 unsigned int myclass::crc32(unsigned int crc, const void *buf, unsigned int   size) { const unsigned int *p;  p = (const quint8 *)buf; crc = crc ^~ 0xffffffff;  while(size--) {     crc = this->crc32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8); }  return crc ^~ 0xffffffff; } 

i call way

 qstring test= qstring::number(mclass.crc32(0, crcval, 6)) 

solution drawn chat dicussion

the crc-32 algorithm being implemented crc-32 ethernet (generator polynomial 0x04c11db7).

this crc-32 requires:

  • being initialized 0xffffffff.
  • and being finalized xoring 0xffffffff.

therefore, should remove crc ^~ 0xffffffff statements within function, pass 0xffffffff on call function, , once you're done crcing data, should xor return value 0xffffffff.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -