Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Pure Python CRC library

License

NotificationsYou must be signed in to change notification settings

Nicoretti/crc

Repository files navigation

Calculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations

Checks MasterCoverageLicenseDownloadsSupported Python VersionsPyPi Package



Available CRC Configurations

For convenience various frequently used crc configurations ship with the library out of the box.

CRC8CRC16CRC32CRC64
CCITTXMODEMCRC32CRC64
AUTOSARGSMAUTOSAR
SAEJ1850PROFIBUSBZIP2
SAEJ1850_ZEROMODBUSPOSIX
BLUETOOTHIBM-3740
MAXIM-DOWKERMIT

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.

Custom Configurations

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.

Requirements

Installation

pip install crc

Examples

Create a Calculator

Pre defined configuration

fromcrcimportCalculator,Crc8calculator=Calculator(Crc8.CCITT)

Custom configuration

fromcrcimportCalculator,Configurationconfig=Configuration(width=8,polynomial=0x07,init_value=0x00,final_xor_value=0x00,reverse_input=False,reverse_output=False,)calculator=Calculator(config)

Calculate a checksum

Standard

fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT)assertexpected==calculator.checksum(data)

Optimized for speed

fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT,optimized=True)assertexpected==calculator.checksum(data)

Verify a checksum

Standard

fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT)assertcalculator.verify(data,expected)

Optimized for speed

fromcrcimportCalculator,Crc8expected=0xBCdata=bytes([0,1,2,3,4,5])calculator=Calculator(Crc8.CCITT,optimized=True)assertcalculator.verify(data,expected)

Calculate a checksum with raw registers

Register

fromcrcimportCrc8,Registerexpected=0xBCdata=bytes([0,1,2,3,4,5])register=Register(Crc8.CCITT)register.init()register.update(data)assertexpected==register.digest()

TableBasedRegister

fromcrcimportCrc8,TableBasedRegisterexpected=0xBCdata=bytes([0,1,2,3,4,5])register=TableBasedRegister(Crc8.CCITT)register.init()register.update(data)assertexpected==register.digest()

References & Resources


[8]ページ先頭

©2009-2025 Movatter.jp