crc


Namecrc JSON
Version 7.0.0 PyPI version JSON
download
home_pagehttps://github.com/Nicoretti/crc
SummaryLibrary and CLI to calculate and verify all kinds of CRC checksums
upload_time2024-04-19 16:26:30
maintainerNicola Coretti
docs_urlNone
authorNicola Coretti
requires_python<4.0,>=3.8
licenseBSD-2-Clause
keywords crc crc8 crc16 crc32 crc64
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">CRC</h1>
<p align="center">

Calculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations
</p>

<p align="center">

<a href="https://github.com/Nicoretti/crc/actions">
    <img src="https://img.shields.io/github/checks-status/nicoretti/crc/master" alt="Checks Master">
</a>
<a href="https://coveralls.io/github/Nicoretti/crc">
    <img src="https://img.shields.io/coverallsCoverage/github/Nicoretti/crc" alt="Coverage">
</a>
<a href="https://opensource.org/licenses/BSD-2-Clause">
    <img src="https://img.shields.io/pypi/l/crc" alt="License">
</a>
<a href="https://pypi.org/project/crc/">
    <img src="https://img.shields.io/pypi/dm/crc" alt="Downloads">
</a>
<a href="https://pypi.org/project/crc/">
    <img src="https://img.shields.io/pypi/pyversions/crc" alt="Supported Python Versions">
</a>
<a href="https://pypi.org/project/crc/">
    <img src="https://img.shields.io/pypi/v/crc" alt="PyPi Package">
</a>
</p>

---
* Documentation: [https://nicoretti.github.io/crc](https://nicoretti.github.io/crc)
* Source Code: [https://github.com/Nicoretti/crc](https://github.com/Nicoretti/crc)
---

## Available CRC Configurations
For convenience various frequently used crc configurations ship with the library out of the box.

| CRC8          | CRC16    | CRC32   | CRC64 |
|---------------|----------|---------|-------|
| CCITT         | XMODEM   | CRC32   | CRC64 |
| AUTOSAR       | GSM      | AUTOSAR |       |
| SAEJ1850      | PROFIBUS | BZIP2   |       |
| SAEJ1850_ZERO | MODBUS   | POSIX   |       |
| BLUETOOTH     | IBM-3740 |         |       |
| MAXIM-DOW     | KERMIT   |         |       | 

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](https://github.com/Nicoretti/crc/pulls) or file an [issue](https://github.com/Nicoretti/crc/issues).

## 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](http://reveng.sourceforge.net/crc-catalogue/all.htm) might help.


## Requirements
* [\>= Python 3.8](https://www.python.org)

## Installation

```shell
pip install crc
```

## Examples

### Create a Calculator

#### Pre defined configuration

```python
from crc import Calculator, Crc8

calculator = Calculator(Crc8.CCITT)
```
#### Custom configuration

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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
-----------------------
* [A Painless guide to crc error detection algorithms](http://www.zlib.net/crc_v3.txt)
* [CRC-Catalogue](http://reveng.sourceforge.net/crc-catalogue/all.htm)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Nicoretti/crc",
    "name": "crc",
    "maintainer": "Nicola Coretti",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": "nico.coretti@gmail.com",
    "keywords": "CRC, CRC8, CRC16, CRC32, CRC64",
    "author": "Nicola Coretti",
    "author_email": "nico.coretti@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/54/39/7e3c6f9af03f0012d4f8ecdf29689fed1f27d57d0f965bf051da4905fa78/crc-7.0.0.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">CRC</h1>\n<p align=\"center\">\n\nCalculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations\n</p>\n\n<p align=\"center\">\n\n<a href=\"https://github.com/Nicoretti/crc/actions\">\n    <img src=\"https://img.shields.io/github/checks-status/nicoretti/crc/master\" alt=\"Checks Master\">\n</a>\n<a href=\"https://coveralls.io/github/Nicoretti/crc\">\n    <img src=\"https://img.shields.io/coverallsCoverage/github/Nicoretti/crc\" alt=\"Coverage\">\n</a>\n<a href=\"https://opensource.org/licenses/BSD-2-Clause\">\n    <img src=\"https://img.shields.io/pypi/l/crc\" alt=\"License\">\n</a>\n<a href=\"https://pypi.org/project/crc/\">\n    <img src=\"https://img.shields.io/pypi/dm/crc\" alt=\"Downloads\">\n</a>\n<a href=\"https://pypi.org/project/crc/\">\n    <img src=\"https://img.shields.io/pypi/pyversions/crc\" alt=\"Supported Python Versions\">\n</a>\n<a href=\"https://pypi.org/project/crc/\">\n    <img src=\"https://img.shields.io/pypi/v/crc\" alt=\"PyPi Package\">\n</a>\n</p>\n\n---\n* Documentation: [https://nicoretti.github.io/crc](https://nicoretti.github.io/crc)\n* Source Code: [https://github.com/Nicoretti/crc](https://github.com/Nicoretti/crc)\n---\n\n## Available CRC Configurations\nFor convenience various frequently used crc configurations ship with the library out of the box.\n\n| CRC8          | CRC16    | CRC32   | CRC64 |\n|---------------|----------|---------|-------|\n| CCITT         | XMODEM   | CRC32   | CRC64 |\n| AUTOSAR       | GSM      | AUTOSAR |       |\n| SAEJ1850      | PROFIBUS | BZIP2   |       |\n| SAEJ1850_ZERO | MODBUS   | POSIX   |       |\n| BLUETOOTH     | IBM-3740 |         |       |\n| MAXIM-DOW     | KERMIT   |         |       | \n\nIf you find yourself in the position, where having a new configuration available out of the\nbox would be desirable, feel free to create a [PR](https://github.com/Nicoretti/crc/pulls) or file an [issue](https://github.com/Nicoretti/crc/issues).\n\n## Custom Configurations\n\nIf you want to create a custom configuration, you should have the following information available:\n\n\ud83d\uddd2 Note:\n\n    This library currently only supports bit widths of full bytes 8, 16, 24, 32, ...\n\n* **width**\n* **polynom**\n* **init value**\n* **final xor value**\n* **reversed input**\n* **reversed output**\n\nIn case you only have a name of a specific crc configuration/algorithm and you are unsure what are the specific parameters\nof it, a look into this [crc-catalogue](http://reveng.sourceforge.net/crc-catalogue/all.htm) might help.\n\n\n## Requirements\n* [\\>= Python 3.8](https://www.python.org)\n\n## Installation\n\n```shell\npip install crc\n```\n\n## Examples\n\n### Create a Calculator\n\n#### Pre defined configuration\n\n```python\nfrom crc import Calculator, Crc8\n\ncalculator = Calculator(Crc8.CCITT)\n```\n#### Custom configuration\n\n```python\nfrom crc import Calculator, Configuration\n\nconfig = Configuration(\n    width=8,\n    polynomial=0x07,\n    init_value=0x00,\n    final_xor_value=0x00,\n    reverse_input=False,\n    reverse_output=False,\n)\n\ncalculator = Calculator(config)\n```\n\n### Calculate a checksum\n\n#### Standard\n\n```python\nfrom crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT)\n\nassert expected == calculator.checksum(data)\n```\n\n#### Optimized for speed\n\n```python\nfrom crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert expected == calculator.checksum(data)\n```\n\n### Verify a checksum\n\n#### Standard\n\n```python\nfrom crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT)\n\nassert calculator.verify(data, expected)\n```\n\n#### Optimized for speed\n\n```python\nfrom crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.verify(data, expected)\n```\n\n### Calculate a checksum with raw registers\n\n#### Register\n\n```python\nfrom crc import Crc8, Register\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\nregister = Register(Crc8.CCITT)\n\nregister.init()\nregister.update(data)\nassert expected == register.digest()\n```\n#### TableBasedRegister\n\n```python\nfrom crc import Crc8, TableBasedRegister\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\nregister = TableBasedRegister(Crc8.CCITT)\n\nregister.init()\nregister.update(data)\nassert expected == register.digest()\n```\n\nReferences & Resources\n-----------------------\n* [A Painless guide to crc error detection algorithms](http://www.zlib.net/crc_v3.txt)\n* [CRC-Catalogue](http://reveng.sourceforge.net/crc-catalogue/all.htm)\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "Library and CLI to calculate and verify all kinds of CRC checksums",
    "version": "7.0.0",
    "project_urls": {
        "Changelog": "https://nicoretti.github.io/crc/changelog/unreleased/",
        "Documentation": "https://nicoretti.github.io/crc/",
        "Homepage": "https://nicoretti.github.io/crc/",
        "Issues": "https://github.com/Nicoretti/crc/issues",
        "Repository": "https://github.com/Nicoretti/crc",
        "Source": "https://github.com/Nicoretti/crc"
    },
    "split_keywords": [
        "crc",
        " crc8",
        " crc16",
        " crc32",
        " crc64"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d4dfc70b599df02a4baa2024564e474e3e9bec4075a6cd869e4983aff5d179a",
                "md5": "e83c554199622c0a37203318d4ee1f62",
                "sha256": "8b22f5534e9360bf61e169ce581d61143d3d0248a1fdc2c4b4f2175af3b2c2aa"
            },
            "downloads": -1,
            "filename": "crc-7.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e83c554199622c0a37203318d4ee1f62",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 8729,
            "upload_time": "2024-04-19T16:26:29",
            "upload_time_iso_8601": "2024-04-19T16:26:29.247187Z",
            "url": "https://files.pythonhosted.org/packages/7d/4d/fc70b599df02a4baa2024564e474e3e9bec4075a6cd869e4983aff5d179a/crc-7.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54397e3c6f9af03f0012d4f8ecdf29689fed1f27d57d0f965bf051da4905fa78",
                "md5": "2a266c5c5dcaef420804661939963e10",
                "sha256": "b9fc521042167f2b59d9183ce27acc0897e4a17748421e8b304ccdf7ebf4280a"
            },
            "downloads": -1,
            "filename": "crc-7.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2a266c5c5dcaef420804661939963e10",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 9793,
            "upload_time": "2024-04-19T16:26:30",
            "upload_time_iso_8601": "2024-04-19T16:26:30.381517Z",
            "url": "https://files.pythonhosted.org/packages/54/39/7e3c6f9af03f0012d4f8ecdf29689fed1f27d57d0f965bf051da4905fa78/crc-7.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-19 16:26:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Nicoretti",
    "github_project": "crc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "crc"
}
        
Elapsed time: 0.23643s