- Notifications
You must be signed in to change notification settings - Fork13
Nicoretti/crc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Calculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations
- Documentation:https://nicoretti.github.io/crc
- Source Code:https://github.com/Nicoretti/crc
For convenience various frequently used crc configurations ship with the library out of the box.
CRC8 | CRC16 | CRC32 | CRC64 |
---|---|---|---|
CCITT | XMODEM | CRC32 | CRC64 |
AUTOSAR | GSM | AUTOSAR | |
SAEJ1850 | PROFIBUS | BZIP2 | |
SAEJ1850_ZERO | MODBUS | POSIX | |
BLUETOOTH | IBM-3740 | ||
MAXIM-DOW | KERMIT |
If you find yourself in the position, where having a new configuration available out of thebox would be desirable, feel free to create aPR or file anissue.
If you want to create a custom configuration, you should have the following information available:
🗒 Note:
This library currently only supports bit widths of full bytes 8, 16, 24, 32, ...
- width
- polynom
- init value
- final xor value
- reversed input
- reversed output
In case you only have a name of a specific crc configuration/algorithm and you are unsure what are the specific parametersof it, a look into thiscrc-catalogue might help.
pip install crc
fromcrcimportCalculator,Crc8calculator=Calculator(Crc8.CCITT)
fromcrcimportCalculator,Configurationconfig=Configuration(width=8,polynomial=0x07,init_value=0x00,final_xor_value=0x00,reverse_input=False,reverse_output=False,)calculator=Calculator(config)
fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT)assertexpected==calculator.checksum(data)
fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT,optimized=True)assertexpected==calculator.checksum(data)
fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT)assertcalculator.verify(data,expected)
fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT,optimized=True)assertcalculator.verify(data,expected)
fromcrcimportCrc8,Registerexpected=0xBCdata=bytes([0,1,2,3,4,5])register=Register(Crc8.CCITT)register.init()register.update(data)assertexpected==register.digest()
fromcrcimportCrc8,TableBasedRegisterexpected=0xBCdata=bytes([0,1,2,3,4,5])register=TableBasedRegister(Crc8.CCITT)register.init()register.update(data)assertexpected==register.digest()
About
Pure Python CRC library