gsutil-mirrors / crcmod Goto Github PK
View Code? Open in Web Editor NEWUnofficial mirror of crcmod (https://bitbucket.org/cmcqueen1975/crcmod). This repository may disappear, so do not depend on it.
License: MIT License
Unofficial mirror of crcmod (https://bitbucket.org/cmcqueen1975/crcmod). This repository may disappear, so do not depend on it.
License: MIT License
=========================== crcmod for Calculating CRCs =========================== The software in this package is a Python module for generating objects that compute the Cyclic Redundancy Check (CRC). There is no attempt in this package to explain how the CRC works. There are a number of resources on the web that give a good explanation of the algorithms. Just do a Google search for "crc calculation" and browse till you find what you need. Another resource can be found in chapter 20 of the book "Numerical Recipes in C" by Press et. al. This package allows the use of any 8, 16, 24, 32, or 64 bit CRC. You can generate a Python function for the selected polynomial or an instance of the Crc class which provides the same interface as the ``md5`` and ``sha`` modules from the Python standard library. A ``Crc`` class instance can also generate C/C++ source code that can be used in another application. ---------- Guidelines ---------- Documentation is available from the doc strings. It is up to you to decide what polynomials to use in your application. If someone has not specified the polynomials to use, you will need to do some research to find one suitable for your application. Examples are available in the unit test script ``test.py``. You may also use the ``predefined`` module to select one of the standard polynomials. If you need to generate code for another language, I suggest you subclass the ``Crc`` class and replace the method ``generateCode``. Use ``generateCode`` as a model for the new version. ------------ Dependencies ------------ Python Version ^^^^^^^^^^^^^^ The package has separate code to support the 2.x and 3.x Python series. For the 2.x versions of Python, these versions have been tested: * 2.4 * 2.5 * 2.6 * 2.7 It may still work on earlier versions of Python 2.x, but these have not been recently tested. For the 3.x versions of Python, these versions have been tested: * 3.1 Building C extension ^^^^^^^^^^^^^^^^^^^^ To build the C extension, the appropriate compiler tools for your platform must be installed. Refer to the Python documentation for building C extensions for details. ------------ Installation ------------ The crcmod package is installed using ``distutils``. Run the following command:: python setup.py install If the extension module builds, it will be installed. Otherwise, the installation will include the pure Python version. This will run significantly slower than the extension module but will allow the package to be used. For Windows users who want to use the mingw32 compiler, run this command:: python setup.py build --compiler=mingw32 install For Python 3.x, the install process is the same but you need to use the 3.x interpreter. ------------ Unit Testing ------------ The ``crcmod`` package has a module ``crcmod.test``, which contains unit tests for both ``crcmod`` and ``crcmod.predefined``. When you first install ``crcmod``, you should run the unit tests to make sure everything is installed properly. The test script performs a number of tests including a comparison to the direct method which uses a class implementing polynomials over the integers mod 2. To run the unit tests on Python >=2.5:: python -m crcmod.test Alternatively, in the ``test`` directory run:: python test_crcmod.py --------------- Code Generation --------------- The crcmod package is capable of generating C functions that can be compiled with a C or C++ compiler. In the test directory, there is an examples.py script that demonstrates how to use the code generator. The result of this is written out to the file ``examples.c``. The generated code was checked to make sure it compiles with the GCC compiler. ------- License ------- The ``crcmod`` package is released under the MIT license. See the ``LICENSE`` file for details. ------------ Contributors ------------ Craig McQueen
Hi all, I would like to implement the following matlab crc check algorithm in Python using crcmod library:
crc8 = comm.CRCGenerator('Polynomial','z^8 + z^2 + z + 1', 'InitialConditions',1,'DirectMethod',true,'FinalXOR',1);
codeword = crc8([0; 0; 1; 0; 0; 1; 1; 1; 1; 0; 1; 0; 0; 1; 1; 1]);
crc= codeword(end-8+1:end)';
I have implemented it in the following way in python:
crc8_func = crcmod.mkCrcFun(0x107, initCrc=1, rev=False, xorOut=1)
crc_received = [0,0,1,0,0,1,1,1,1,0,1,0,0,1,1,1]
crc = crc8_func(bytes(crc_received))
The expected result should be:
10010001 (binary) or 145 (decimal) or 91 (hex)
But instead I get:
10101001 in binary. Do you know what I am doing wrong?
Thanks in advance for the help.
I (Craig McQueen) am not the original author of crcmod; Ray Buvel is.
The repository at https://bitbucket.org/cmcqueen1975/crcmod is my repository, but it is a fork of Ray Buvel's code. I made some contributions to crcmod a number of years ago, hence the existence of my BitBucket repository for my work on my contributions to it.
Ray Buvel's original crcmod project is on SourceForge:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.