Perform CRC with arbitrary order polynomials on data with an arbitrary length accelerated with lookup tables.
- You need to support a polynomial that's not a multiple of 8 bits long.
- You need to support data that's not a multiple of 8 bits long.
- It needs to be relatively fast.
You can use the BitCrc class directly
from bitcrc_python import BitCrc
# Our polynomial is 0x1021, 16 bits long
crc = BitCrc(16, 0x1021, initialValue=0xFFFF, xorOut=0xFFFF)
checksum = crc.generate("Hello World")
assert(checksum == 0x4D25)
Or drop the library in as a replacement for crcmod
from bitcrc_python import crcmod
# Instead of specifying the length with crcmod
# you just need to include the leading bit.
crc = crcmod.mkCrcFun(0x11021, initCrc=0xFFFF)
checksum = crc("Hello world")
assert(checksum == 0x4D25)
Licensed under the MIT License, refer to LICENSE.md for more information.