Skip to main content

CRC

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

Checks Master Coverage License Downloads Supported Python Versions PyPi Package



Available CRC Configurations

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 the box would be desirable, feel free to create a PR or file an issue.

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 parameters of it, a look into this crc-catalogue might help.

Requirements

Installation

pip install crc

Examples

Create a Calculator

Pre defined configuration

from crc import Calculator, Crc8

calculator = Calculator(Crc8.CCITT)

Custom configuration

from crc import Calculator, Configuration

config = 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

from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT)

assert expected == calculator.checksum(data)

Optimized for speed

from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT, optimized=True)

assert expected == calculator.checksum(data)

Verify a checksum

Standard

from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT)

assert calculator.verify(data, expected)

Optimized for speed

from crc import Calculator, Crc8

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
calculator = Calculator(Crc8.CCITT, optimized=True)

assert calculator.verify(data, expected)

Calculate a checksum with raw registers

Register

from crc import Crc8, Register

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
register = Register(Crc8.CCITT)

register.init()
register.update(data)
assert expected == register.digest()

TableBasedRegister

from crc import Crc8, TableBasedRegister

expected = 0xBC
data = bytes([0, 1, 2, 3, 4, 5])
register = TableBasedRegister(Crc8.CCITT)

register.init()
register.update(data)
assert expected == register.digest()

References & Resources

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crc-8.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crc-8.0.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file crc-8.0.0.tar.gz.

File metadata

  • Download URL: crc-8.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for crc-8.0.0.tar.gz
Algorithm Hash digest
SHA256 e1ef893b042c26c9f47fd32f3c17507b7d1bd81169acebaef908774856fdaa3e
MD5 fc406fc84867b2f2549eb6dc45be8a2b
BLAKE2b-256 48b879b2c41836b5f8503342956ef31218059159a3f556c31e76ef5c14233d4b

See more details on using hashes here.

File details

Details for the file crc-8.0.0-py3-none-any.whl.

File metadata

  • Download URL: crc-8.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for crc-8.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c3603d5d8f5b241ba7fcc466b1fa9b0cbcbf45ebeaf5598c46dd4dcfb9e396e
MD5 fa8e819e9e3f13d137ca9d146a595ed7
BLAKE2b-256 5f444ab29e156d516c5bcca080e5dd3569dc41c41c09998fac34c7b42e5956c6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

8.0.0 This release

2 files

7.1.0

2 files

7.0.0

2 files

6.1.2

2 files

6.1.1

2 files

6.1.0

2 files

6.0.0

2 files

5.0.0

2 files

4.3.0

2 files

4.2.0

2 files

4.1.0

2 files

4.0.0

2 files

3.0.1

2 files

3.0.0

2 files

2.0.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.3

1 file

1.1.2

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.10.0

1 file

0.9.5

1 file

0.9.4

1 file

0.9.3

1 file

0.9.2

1 file

0.9.1

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.3.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page