Skip to main content

Pure Python CRC library

Project description

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

Project details


Download files

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

Source Distribution

crc-7.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: crc-7.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.18 Linux/6.5.0-1025-azure

File hashes

Hashes for crc-7.1.0.tar.gz
Algorithm Hash digest
SHA256 99dd540909a37ae4f62c65441df8ecb4e7f9af014fecaf4f331052a41d66c07d
MD5 cca626fb7bc30b4c468216ca67ee21c2
BLAKE2b-256 7ee6c3488c35ecae290751466252e5ea01ef50fc67bfc1a9aba43983329b7025

See more details on using hashes here.

File details

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

File metadata

  • Download URL: crc-7.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.18 Linux/6.5.0-1025-azure

File hashes

Hashes for crc-7.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9845c81d0b900d8fda1aae7af977035bee0359c279713814e9fd23a2d59db6a
MD5 ea78e918b1ccd55b1681608aaf98a4e6
BLAKE2b-256 dfff5ebeae9b53e8cddd9e6f3b6b0c98da3f112d9a7e1ea638a00876aa8fb5b4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page