pycrc provides CRC reference implementations in Python and a
C source code generator.
The used CRC variant can be chosen from a fast but space-consuming implementation to slower but smaller versions
especially suitable for embedded applications.
The models can be freely chosen, and the collection of CRC models
lists some of the most popular models by name.
The following functions are implemented:
- calculate the checksum of a string or a file.
generate the source files for a
The following variants of the CRC algorithm are supported:
- bit-by-bit: the basic algorithm which operates individually on every bit of the augmented message (i.e. the input data with Width zero bits added at the end). This algorithm is a straightforward implementation of the basic polynomial division and is the easiest one to understand, but it is also the slowest one among all possible variants.
- bit-by-bit-fast: a variation of the simple bit-by-bit algorithm. This algorithm still iterates over every bit of the message, but does not augment it (does not add Width zero bits at the end). It gives the same result as the bit-by-bit method by carefully choosing the initial value of the algorithm. This method might be a good choice for embedded platforms, where code space is more important than execution speed.
- table-driven: the standard table driven algorithm. This is the fastest variant because it operates on one byte at a time, as opposed to one bit at the time. This method uses a look-up table (usually of 256 elements), which might not be acceptable for small embedded systems. The number of elements in the look-up table can be reduced with the --table-idx-width command line switch. The value of 4 bits for the table index (16 elements in the look-up table) can be a good compromise between execution speed and code size.
pycrc is released under the terms of the MIT licence.
- The Man page is the most comprehensive source of information.
- The Tutorial how to use the generated source code in your program.
- CRC generator documentation of the
- List of supported CRC models.
- FAQ Frequently Asked Questions.
- Subscribe to the pycrc-users Mailing list.
- If you have found a bug or want to request a feature, please submit it to the pycrc Issue Tracker.
- Contact the author at <email@example.com>.
If you like pycrc and you would like to give something back, then please see some ways how to say thanks.
The latest released version is:
To Do ¶
pycrc is considered stable code. No new features are planned, but bugs are still fixed and new models added on request.
Check out the pycrc issue tracker for open bugs and feature requests.
CRC links ¶
- Ross N. Williams' Painless Guide to CRC Error Detection Algorithms is a very good starting point to understand CRC algorithms.
- The online CRC calculator has been heavily used in the early stage of pycrc. It is a very good place to test your CRC implementation and the
Cimplementation on this site is worth studying.
- The Wikipedia-page on Cyclic redundancy check contains a rather scientific (i.e. dry) explanation of the matter, but the links on the bottom of the page are very useful.
- The Catalogue of parametrised CRC Algorithms by Greg Cook contains a lot of useful information about CRC variants.
- Terry Ritter's The Great CRC Mystery is another good place to study CRC algorithms.
- Sometimes the result of a CRC calculation is known but not the parameters. In that case Gregory Ewing's article Reverse-Engineering a CRC Algorithm comes handy. It outlines an algorithm how to get the CRC parameters from raw data. Greg Cook's Perl script CRC RevEng does a good job in finding the parameters from a few data points.
Other Free CRC tools ¶
- crc-generator is a Python module which calculates the CRC and generates
Csource code. (MIT licence)
- CrcMoose is another CRC Python module, able to generate a CRC of arbitrary models and it contains a long list of CRC models. (MIT licence)
- Universal Crc is a
Cprogram that generates fast
Csource code. It is noteworthy that it can generate a table-driven algorithm for polynomials which do not have to be 8-bit aligned. (GPL licence)
The source code for pycrc is on GitHub.