I'm trying to evaluate appropriate checksum based on CRC-16 algorithm using crcmod Python module and 2.7 version of Python interpreter. The checksum parameters are:
- CRC order: 16
- CRC polynomial: 0x8005
- Inital value: 0xFFFF
- Final value: 0x0000
- Direct: True
Code:
crc16 = crcmod.mkCrcFun(0x18005, rev=False, initCrc=0xFFFF, xorOut=0x0000)
print hex(crc16(str(int(0x5A0001))))
and for the input 0x5A0001 it prints 0x7E16 while I should get something like 0xCE0A.
I checked on http://www.lokker.net/Java/crc/CRCcalculation2.htm and the computed value is 0xACE which is correct (with respect to the order).
0x18005as your polynomial in the python code, but you listed0x8005in your checksum parameters above. - djhoese0x18005is correct forcrcmod. That package determines the number of bits in the CRC from the complete polynomial. It is common to provide a CRC polynomial without the high term, e.g.0x8005and separately specify that it is a 16-bit CRC. - Mark Adlerc16and then tried to usecrc16. Did you meanc16? Second, what exactly do you think you are computing the CRC of? You do know thatstr(int(0x5A0001))returns the string of ASCII digits5898241, yes? What did you input into the web CRC calculator? - Mark Adlerbinascii.crc_hqx(data, 0): docs here - hoc_age