Skip to main content

Library and CLI to calculate and verify all kinds of CRC checksums

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 convince various frequently used crc configurations ship with the library out of the box.

CRC8 CRC16 CRC32 CRC64
CCITT CCITT CRC32 CRC64
AUTOSAR GSM AUTOSAR
SAJ1850 PROFIBUS BZIP2
BLUETOOTH POSIX
MAXIM-DOW

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-4.0.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

crc-4.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: crc-4.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.15 Linux/5.15.0-1024-azure

File hashes

Hashes for crc-4.0.0.tar.gz
Algorithm Hash digest
SHA256 8475fd62b5b227af91520418fd764d282e75f190f3806c54b9225f0b0699e5a9
MD5 c8f8cdaad249175da890a61467c30008
BLAKE2b-256 2406bf88a98cfcbe89f2040cf20819bad3bc29e2fc238f9d7f34a59e0be6e2d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: crc-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.15 Linux/5.15.0-1024-azure

File hashes

Hashes for crc-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbb6e469d8087f86ab3fc1907fe209e566751487cb58f03c0dc96d03b671a1f5
MD5 b9315120149ae3953e2f4f6289da089d
BLAKE2b-256 0ccaeee3466845987a07999fae111a80d4742e33d274ac52cf2c4e1a7c70c802

See more details on using hashes here.

Supported by

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