Skip to main content

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

Project description

Overview

coveralls pypi-package-available

Library and CLI tool for calculating and verifying CRC checksums.

Provided Default Configuration(s) of CRC Algorithms:

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

Requirements

  • Python 3.7 and newer

Examples

Calculate crc using the CrcCalculator

from crc import CrcCalculator, Crc8
data = bytes([0, 1, 2, 3, 4, 5 ])
expected_checksum = 0xBC
crc_calculator = CrcCalculator(Crc8.CCITT)

checksum = crc_calculator.calculate_checksum(data)

assert checksum == expected_checksum
assert crc_calculator.verify_checksum(data, expected_checksum)

Speed up the calculation by using a table based CrcCalculator

from crc import CrcCalculator, Crc8

data = bytes([0, 1, 2, 3, 4, 5 ])
expected_checksum = 0xBC
use_table = True
crc_calculator = CrcCalculator(Crc8.CCITT, use_table)

checksum = crc_calculator.calculate_checksum(data)

assert checksum == expected_checksum
assert crc_calculator.verify_checksum(data, expected_checksum)

Create a custom crc configuration for the crc calculation

from crc import CrcCalculator, Configuration

data = bytes([0, 1, 2, 3, 4, 5 ])
expected_checksum = 0xBC

width = 8
poly=0x07
init_value=0x00
final_xor_value=0x00
reverse_input=False
reverse_output=False

configuration = Configuration(width, poly, init_value, final_xor_value, reverse_input, reverse_output)

use_table = True
crc_calculator = CrcCalculator(configuration, use_table)

checksum = crc_calculator.calculate_checksum(data)
assert checksum == expected_checksum
assert crc_calculator.verify_checksum(data, expected_checksum)

Use bare bones crc registers

from crc import Crc8, TableBasedCrcRegister, CrcRegister

data = bytes([0, 1, 2, 3, 4, 5 ])
expected_checksum = 0xBC

reg = CrcRegister(Crc8.CCITT)
table_reg = TableBasedCrcRegister(Crc8.CCITT)

reg.init()
reg.update(data)
assert expected_checksum == reg.digest()

table_reg.init()
table_reg.update(data)
assert expected_checksum == table_reg.digest()

Command line tool

See crc --help

subcommand(s)

table

Subcommand to pre-compute crc lookup tables. See also crc table --help.

checksum

Subcommand to calculate crc checksums of input file(s). See also crc checksum --help.

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

Uploaded Source

Built Distribution

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

crc-1.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: crc-1.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.2.0

File hashes

Hashes for crc-1.2.0.tar.gz
Algorithm Hash digest
SHA256 1f7e797847e388535d3bbf6ca8e1a7c97c4cbd3d6d298033192f9936460c60c5
MD5 af341f59dbe1613bd51ec61270506802
BLAKE2b-256 a871748e4dfddea00d80f9703165903af6696cdf95df82e075771e41d92c989d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: crc-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Darwin/21.2.0

File hashes

Hashes for crc-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 311d9144bf966f72d89b512f460cef4e8a1fdf971683c73dd002bc0f6e2994e1
MD5 608cf7317e7b40cbfe5aa756b7b44182
BLAKE2b-256 344e9034a6f4643ffada9a5f7ba76e56fe730f403ec3e8b5441134eef90b991b

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