Skip to main content

A library for CRC calculation

Project description

https://img.shields.io/pypi/v/crcengine.svg https://travis-ci.com/GardenTools/CrcEngine.svg?branch=master Documentation Status Updates

CrcEngine

A python library for CRC calculation providing table-based as well as bit-bashing implementations (for reference).

Installing

CrcEngine can be installing using pip with

pip install crcengine

Usage

Pre-defined algorithms such as CRC32 are available. Tailored algorithms can be created by calling CrcEngine.create() and other related methods.

A calculation engine for a specific named algorithm can be obtained using CrcEngine.new(). Algorithms which are not pre-defined can be created using CrcEngine.create()

A list of pre-defined algorithms can be obtained using crcengine.algorithms_available()

>>> list(crcengine.algorithms_available())
['crc8', 'crc8-autosar', 'crc8-bluetooth', 'crc8-ccitt', 'crc8-gsm-b', 'crc8-sae-j1850', 'crc15-can', 'crc16-kermit', 'crc16-ccitt-true', 'crc16-xmodem', 'crc16-autosar', 'crc16-ccitt-false', 'crc16-cdma2000', 'crc16-ibm', 'crc16-modbus', 'crc16-profibus', 'crc24-flexray16-a', 'crc24-flexray16-b', 'crc32', 'crc32-bzip2', 'crc32-c', 'crc64-ecma']

Examples

Using a pre-defined algorithm

import crcengine
crc_algorithm = crcengine.new('crc32-bzip2')
result = crc_algorithm(b'123456789')
print('CRC=0x{:08x}'.format(result))

Output: > CRC=0xfc891918

Defining an algorithm

import crcengine
crc_openpgp = crcengine.create(0x864cfb, 24, 0xb704ce, ref_in=False,
                               ref_out=False, xor_out=0, name='crc-24-openpgp')

Code Generation

The library can generate C code for a given table-algorithm. The code produced is intended to be a reasonable compromise between size, complexity and speed without requiring allocation of memory for table generation at runtime.

Faster implementations of specific algorithms can be achieved in software which unroll loops and pipeline the operations different bytes to introduce parallelism in the calculation see intel_soft_src for example. Some processors also include instructions specifically for crc calculation.

Code Generation Example usage:

Generating code into a directory named “out” by passing CRC parameters

params = crcengine.get_algorithm_params('crc32')
crcengine.generate_code(params, 'out/')

or referencing the algorithm by name

crcengine.generate_code('crc16-xmodem', 'out/')

Downloading

Builds

CI builds for pull requests are performed on travis_ci


With thanks to Greg Cook for providing such a thoroughly collated list of CRC definitions

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

crcengine-0.2.0.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

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

crcengine-0.2.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file crcengine-0.2.0.tar.gz.

File metadata

  • Download URL: crcengine-0.2.0.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.4

File hashes

Hashes for crcengine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e39cac44c71967fb2d2c0744a2a06f6f0bd05ab416216428ded7157fbfd0bdf6
MD5 d91c547e398f752d49c3940d0fc9aeba
BLAKE2b-256 d0e6dfa0e6bfacaed0186b41c19ae70b0d33d92b3efe907193334051a32638ba

See more details on using hashes here.

File details

Details for the file crcengine-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: crcengine-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.4

File hashes

Hashes for crcengine-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91d984421441d1931426683ba3fe906be99270a7ccedc74c0bc02584a17d9e4e
MD5 eeb882ae2d6faa60809c6a3ebce93b55
BLAKE2b-256 89b57adb0339eb0eaceb8614438641ec3414cb61b9dce9ba9d662ae3fe75274b

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