├── .idea
├── .name
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
├── modules.xml
├── misc.xml
└── crccheck.iml
├── .gitignore
├── docs
├── source
│ ├── modules.rst
│ ├── index.rst
│ ├── crccheck.rst
│ ├── changelog.rst
│ ├── howto.rst
│ ├── conf.py
│ └── crctable.rst
└── build.bat
├── .github
└── workflows
│ └── pypi-publish.yml
├── .coveragerc
├── LICENSE.txt
├── tests
├── __init__.py
├── test_reflectbitorder.py
├── test_checksum.py
├── test_base.py
└── test_crc.py
├── pyproject.toml
├── Makefile
├── create
├── crctable.py
└── dl.py
├── README.rst
└── crccheck
├── __init__.py
├── __main__.py
├── checksum.py
└── base.py
/.idea/.name:
--------------------------------------------------------------------------------
1 | crccheck
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .coverage
2 | .idea
3 | /build
4 | /dist
5 | *.pyc
6 | /crccheck.egg-info
7 | docs/build
8 |
--------------------------------------------------------------------------------
/docs/source/modules.rst:
--------------------------------------------------------------------------------
1 | crccheck
2 | ========
3 |
4 | .. toctree::
5 | :maxdepth: 4
6 |
7 | crccheck
8 |
--------------------------------------------------------------------------------
/docs/build.bat:
--------------------------------------------------------------------------------
1 | set PYTHONPATH=..
2 | python ../create/crctable.py > source/crctable.rst
3 | sphinx-apidoc -f -o source ../crccheck
4 | sphinx-build -b html source build
5 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/docs/source/index.rst:
--------------------------------------------------------------------------------
1 | ========
2 | crccheck
3 | ========
4 |
5 | .. automodule:: crccheck
6 |
7 | Contents:
8 |
9 | .. toctree::
10 | :maxdepth: 2
11 |
12 | crccheck
13 | crctable
14 | howto
15 | changelog
16 |
17 | Indices and tables
18 | ==================
19 |
20 | * :ref:`genindex`
21 | * :ref:`modindex`
22 | * :ref:`search`
23 |
24 |
--------------------------------------------------------------------------------
/docs/source/crccheck.rst:
--------------------------------------------------------------------------------
1 | crccheck package
2 | ================
3 |
4 | Submodules
5 | ----------
6 |
7 | crccheck.base module
8 | --------------------
9 |
10 | .. automodule:: crccheck.base
11 | :members:
12 | :undoc-members:
13 | :show-inheritance:
14 |
15 | crccheck.checksum module
16 | ------------------------
17 |
18 | .. automodule:: crccheck.checksum
19 | :members:
20 | :undoc-members:
21 | :show-inheritance:
22 |
23 | crccheck.crc module
24 | -------------------
25 |
26 | .. automodule:: crccheck.crc
27 | :members:
28 | :undoc-members:
29 | :show-inheritance:
30 |
31 | Module contents
32 | ---------------
33 |
34 | .. automodule:: crccheck
35 | :members:
36 | :undoc-members:
37 | :show-inheritance:
38 |
--------------------------------------------------------------------------------
/.github/workflows/pypi-publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish to PyPI
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v*' # e.g., v1.0.0
7 |
8 | jobs:
9 | build-and-publish:
10 | name: Build and publish Python package
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - name: Checkout code
15 | uses: actions/checkout@v4
16 |
17 | - name: Set up Python
18 | uses: actions/setup-python@v5
19 | with:
20 | python-version: '3.11'
21 |
22 | - name: Install build tool
23 | run: |
24 | python -m pip install --upgrade build
25 |
26 | - name: Build package
27 | run: |
28 | python -m build
29 |
30 | - name: Publish to PyPI
31 | uses: pypa/gh-action-pypi-publish@release/v1
32 | with:
33 | password: ${{ secrets.PYPI_API_TOKEN }}
34 |
35 |
--------------------------------------------------------------------------------
/.coveragerc:
--------------------------------------------------------------------------------
1 | # .coveragerc to control coverage.py
2 | [run]
3 | branch = True
4 | omit = *mock*, *pbr*, *six*, *funcsigs*, *encodings*
5 |
6 | [report]
7 | # Regexes for lines to exclude from consideration
8 | exclude_lines =
9 | # Have to re-enable the standard pragma
10 | pragma: no cover
11 |
12 | # Ignore backward compatibility code
13 | if sys.version_info < (3, 3, 0):
14 |
15 | # Don't complain about missing debug-only code:
16 | def __repr__
17 | if self\.debug
18 |
19 | # Don't complain if tests don't hit defensive assertion code:
20 | raise AssertionError
21 | raise NotImplementedError
22 |
23 | # Don't complain if non-runnable code isn't run:
24 | if 0:
25 | if __name__ == .__main__.:
26 | mock
27 | pbr
28 | six
29 |
30 | omit =
31 | tests/__init__.py
32 | tests/*
33 |
34 |
35 | ignore_errors = True
36 |
37 | [html]
38 | directory = coverage_html_report
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2015-2025 Martin Scharrer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.idea/crccheck.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
1 | """Test modules for crccheck package.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | import random
26 | from unittest import TestCase
27 |
28 | try:
29 | from random import randbytes
30 | except ImportError:
31 | def randbytes(length):
32 | return [random.randint(0, 255) for _ in range(0, length)]
33 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | # for the license of this file see LICENSE.txt
2 |
3 | [build-system]
4 | requires = ["setuptools>=61.2", "setuptools_scm[toml]>=7"]
5 | build-backend = "setuptools.build_meta"
6 |
7 | [project]
8 | name = "crccheck"
9 | authors = [{name = "Martin Scharrer", email = "martin.scharrer@web.de"}]
10 | license = {text = "MIT"}
11 | description = "Calculation library for CRCs and checksums"
12 | readme = "README.rst"
13 | classifiers = [
14 | "Development Status :: 5 - Production/Stable",
15 | "License :: OSI Approved :: MIT License",
16 | "Intended Audience :: Developers",
17 | "Intended Audience :: Information Technology",
18 | "Operating System :: OS Independent",
19 | "Programming Language :: Python :: 3.7",
20 | "Programming Language :: Python :: 3.8",
21 | "Programming Language :: Python :: 3.9",
22 | "Programming Language :: Python :: 3.10",
23 | "Programming Language :: Python :: 3.11",
24 | "Programming Language :: Python :: 3.12",
25 | "Programming Language :: Python :: 3.13",
26 | "Topic :: Scientific/Engineering",
27 | "Topic :: Software Development :: Embedded Systems",
28 | "Topic :: Utilities",
29 | ]
30 | dependencies = []
31 | dynamic = ["version"]
32 |
33 | [project.urls]
34 | Homepage = "https://github.com/MartinScharrer/crccheck"
35 |
36 | [tool.setuptools]
37 | include-package-data = false
38 | license-files = ["LICENSE.txt"]
39 |
40 | [tool.setuptools.packages.find]
41 | include = ["crccheck", "crccheck.*"]
42 |
43 | [tool.setuptools_scm]
44 | version_scheme = "guess-next-dev"
45 | local_scheme = "node-and-date"
46 |
--------------------------------------------------------------------------------
/docs/source/changelog.rst:
--------------------------------------------------------------------------------
1 | =========
2 | Changelog
3 | =========
4 |
5 | v1.3.0 - 2022-10-13
6 | ===================
7 | * Updated unit tests to use correct asserts.
8 | * Some code quality adjustments.
9 | * Switched license from GPLv3 to MIT.
10 |
11 | v1.2.0 - 2022-10-06
12 | ===================
13 | * Updated with newest CRC from catalogue.
14 | * Changed project repository from Mercurial to Git.
15 |
16 | v1.1.1 - 2022-10-06
17 | ===================
18 | * Switched unit tests from nose to unittest module.
19 |
20 | v1.1 - 2021-11-25
21 | =================
22 | * Fixed ignored byteorder in calchex().
23 | * Updated documentation.
24 |
25 | v1.0 - 2020-09-21
26 | =================
27 | * Added further CRCs.
28 | * Fixed missing storage of initial value for general ``Crc`` class. Before ``reset()`` did not work correctly.
29 | * Updated tests to achieve 100% code coverage.
30 |
31 | v0.6 - 2016-04-03
32 | =================
33 | * Added compatibility with Python 2.7 and 3.3.
34 |
35 | v0.5 - 2016-03-30
36 | =================
37 | * Added general checksum classes Checksum and ChecksumXor.
38 | * changed ``process()`` to return ``self`` so that calls can be chained.
39 | * changed ``init()`` to return ``self`` so that calls can be chained.
40 | * renamed ``init()`` to ``reset()``.
41 | * Updated documentation.
42 |
43 | v0.4 - 2016-03-29
44 | =================
45 | * Removed arguments startindex and endindex as they are not required.
46 | * Optimized reflectbitorder().
47 | * base: Added ``byteorder`` argument to ``calchex()``.
48 | * Removed outdated code.
49 | * Added more unit tests.
50 |
51 | v0.3 - 2016-03-28
52 | =================
53 | * Renamed package to ``crccheck`` as old name was taken in PIP.
54 | * Changed ``bigendian=True/False`` arguments to ``byteorder='big'/'little'``.
55 | * Added more docstring documentation.
56 | * Removed outdated code from repository.
57 |
58 | v0.2 - 2016-03-27
59 | =================
60 | * Changes to support Python 3.
61 | * Code reformatting.
62 | * Some smaller fixes.
63 | * Runtime optimisations.
64 |
65 | v0.1 - 2015-09-23
66 | =================
67 | * First version.
68 |
--------------------------------------------------------------------------------
/docs/source/howto.rst:
--------------------------------------------------------------------------------
1 | ======
2 | How-to
3 | ======
4 |
5 |
6 | How to quickly calculate a CRC/checksum
7 | =======================================
8 | If only one data buffer needs to be processed a CRC/checksum can be generated quickly using the class method
9 | :meth:`.calc`::
10 |
11 | from crccheck.crc import Crc32
12 | crc = Crc32.calc(data)
13 |
14 | If the result is needed as hexstring or bytes use :meth:`.calchex` or :meth:`.calcbytes`, respectively.
15 |
16 |
17 |
18 | How to calculate over multiple data blocks
19 | ==========================================
20 | Create an instance and feed all data blocks to :meth:`.process`.
21 | Once done, use :meth:`.final` to get the final result::
22 |
23 | from crccheck.crc import Crc32
24 | crcinst = Crc32()
25 | crcinst.process(data1)
26 | crcinst.process(data2)
27 | crcinst.process(data3)
28 | crc = crcinst.final()
29 |
30 | The intermediate value can be read using :meth:`.value` and, if required, set again using :meth:`.init`.
31 |
32 |
33 |
34 | How to use a CRC not implemented by the package
35 | ===============================================
36 | The package implements all CRCs listed in the
37 | `Catalogue of parametrised CRC algorithms `_.
38 |
39 | The general class :class:`crccheck.crc.Crc` can be used for any other CRCs.
40 | You need to provide the CRC parameters. These are described in detail in the publication
41 | `A paninless guide to CRC error detection alogithms `_.
42 |
43 | For advanced users is also possible to create an own subclass. See the source code for details.
44 |
45 |
46 |
47 | How to calculate the CRC or checksum of a file
48 | ==============================================
49 |
50 | You need to provide an interable over all bytes in the file.
51 | For this `mmap `_ is recommended::
52 |
53 | from mmap import ACCESS_READ, mmap
54 | from crccheck.crc import Crc32
55 |
56 | with open("somefile.ext", 'rb') as fh, mmap(fh.fileno(), 0, access=ACCESS_READ) as mm:
57 | crc = Crc32.calc((b[0] for b in mm))
58 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | ###################################################################################################
2 | # License:
3 | # MIT License
4 | #
5 | # Copyright (c) 2015-2022 by Martin Scharrer
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software
8 | # and associated documentation files (the "Software"), to deal in the Software without
9 | # restriction, including without limitation the rights to use, copy, modify, merge, publish,
10 | # distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
11 | # Software is furnished to do so, subject to the following conditions:
12 | #
13 | # The above copyright notice and this permission notice shall be included in all copies or
14 | # substantial portions of the Software.
15 | #
16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
17 | # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | #
22 | ###################################################################################################
23 |
24 | .PHONY: all test Install plugins dist clean doc release
25 |
26 | all: test
27 |
28 | test:
29 | @echo ""; echo "Running tests:"
30 | @python -m coverage run --branch -m unittest discover
31 | @python -m coverage report
32 | @python -m coverage html
33 |
34 | coverage: test
35 |
36 | dist: test
37 | @python -m build
38 |
39 |
40 | clean:
41 | @${RM} -rf dist bdist build */__pycache__ */*.pyc *.egg-info coverage_html_report
42 |
43 |
44 | doc:
45 | @echo ""; echo "Extracting documentation:"
46 | @cd docs/; export PYTHONPATH=..; python ../create/crctable.py > source/crctable.rst
47 | @cd docs/; sphinx-apidoc -f -o source ../crccheck
48 | @cd docs/; sphinx-build -b html source build
49 |
50 |
51 | update:
52 | @test -z "$$(git status --porcelain crccheck/crc.py)" || (echo "crccheck/crc.py has uncommitted changes. Aborting!" && exit 1)
53 | @cd create/; python dl.py ../crccheck/crc.py
54 | @test -z "$$(git status --porcelain crccheck/crc.py)" || echo "crccheck/crc.py has been updated."
55 |
56 |
57 | release: clean test doc dist
58 |
59 |
--------------------------------------------------------------------------------
/tests/test_reflectbitorder.py:
--------------------------------------------------------------------------------
1 | """ Unit tests for reflectbitorder function.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | from crccheck.base import reflectbitorder
26 | from tests import TestCase
27 |
28 |
29 | class TestReflectBitOrder(TestCase):
30 |
31 | def test_1(self):
32 | self.assertEqual(reflectbitorder(8, 0x80), 0x01)
33 |
34 | def test_2(self):
35 | self.assertEqual(reflectbitorder(16, 0x8000), 0x0001)
36 |
37 | def test_3(self):
38 | self.assertEqual(reflectbitorder(8, 0x81), 0x81)
39 |
40 | def test_4(self):
41 | self.assertEqual(reflectbitorder(80, (1 << 79)), 0x01)
42 |
43 | def test_5(self):
44 | self.assertEqual(reflectbitorder(65, 0x1), (1 << 64))
45 |
46 | def test_6(self):
47 | self.assertEqual(reflectbitorder(3, 0b110), 0b011)
48 |
49 | def test_7(self):
50 | self.assertEqual(reflectbitorder(3, 0b110), 0b011)
51 |
52 | def test_8(self):
53 | self.assertEqual(reflectbitorder(0, 0), 0)
54 |
55 | def expect(self, w, v, e):
56 | self.assertEqual(reflectbitorder(w, v), e)
57 |
58 | def test_random(self):
59 | import random
60 | random.seed()
61 | for width in range(1, 125):
62 | # noinspection PyUnusedLocal
63 | randombitstr = "".join([str(random.randint(0, 1)) for m in range(0, width)])
64 | value = int(randombitstr, 2)
65 | expectedresult = int("".join(reversed(randombitstr)), 2)
66 | with self.subTest(width=width):
67 | self.expect(width, value, expectedresult)
68 |
--------------------------------------------------------------------------------
/create/crctable.py:
--------------------------------------------------------------------------------
1 | from crccheck.crc import ALLCRCCLASSES
2 | import crccheck.crc as crcmodule
3 | from dl import aliases, getclassname
4 |
5 | head = """\
6 | Supported CRCs
7 | ==============
8 |
9 | """
10 |
11 |
12 | fmts = (
13 | '{: <{}s}', '{: <{}s}', '{: <{}d}', '0x{: <{}X}', '0x{: <{}X}',
14 | '{!s: <{}s}', '{!s: <{}s}', '0x{: <{}X}', '0x{: <{}X}', '0x{: <{}X}'
15 | )
16 |
17 | table_head = (
18 | 'CRC Name', 'Class', 'Bit width', 'Poly', 'Initvalue', 'Reflect input',
19 | 'Reflect output', 'XOR output', 'Check', 'Residue'
20 | )
21 |
22 | table = []
23 |
24 | for c in ALLCRCCLASSES:
25 | c._crcname = c.__doc__.splitlines()[0]
26 | table.append((
27 | c._crcname, c.__name__, c._width, c._poly, c._initvalue,
28 | c._reflect_input, c._reflect_output, c._xor_output,
29 | c._check_result, c._residue
30 | ))
31 |
32 | # get column width
33 |
34 | lengths = list(max(len(fmts[col].format(row[col], 0)) for row in table) for col in range(len(table[0])))
35 | lengths = list(max((a, len(b))) for a, b in zip(lengths, table_head))
36 |
37 | tlengths = [l + (2 if fmts[n].startswith('0x') else 0) for n, l in enumerate(lengths)]
38 |
39 | print(head)
40 |
41 | print('+', end='')
42 | print('+'.join('-' * (tlengths[n] + 2) for n in range(len(table_head))), end='')
43 | print('+')
44 |
45 | print('| ', end='')
46 | print(' | '.join('{: <{}s}'.format(content, tlengths[n]) for n, content in enumerate(table_head)), end='')
47 | print(' |')
48 |
49 | print('+', end='')
50 | print('+'.join('=' * (tlengths[n] + 2) for n in range(len(table_head))), end='')
51 | print('+')
52 |
53 | for row in table:
54 | print('| ', end='')
55 | print(' | '.join(fmts[n].format(content, lengths[n]) for n, content in enumerate(row)), end='')
56 | print(' |')
57 | print('+', end='')
58 | print('+'.join('-' * (tlengths[n] + 2) for n in range(len(row))), end='')
59 | print('+')
60 |
61 | #
62 | # print("".join(template.format(c=c) for c in ALLCRCCLASSES))
63 |
64 |
65 | print("""
66 |
67 | Aliases
68 | -------
69 |
70 | As some CRCs are also known under different names aliases for the CRC classes are defined.
71 |
72 | """)
73 |
74 | al = sorted(((name, getclassname(name), getattr(crcmodule, getclassname(name))) for name in aliases.keys()), key=lambda x: x[2]._width)
75 | table = [('CRC', 'Class', 'Alias', 'Alias Classes')]
76 | table.extend((a[0], a[1], ', '.join(aliases[a[0]]), ', '.join(getclassname(name) for name in aliases[a[0]])) for a in al)
77 | lengths = list(max(len(row[col]) for row in table) for col in range(4))
78 |
79 | print('+', end='')
80 | print('+'.join('-' * (lengths[n] + 2) for n in range(len(table[0]))), end='')
81 | print('+')
82 |
83 | print('| ', end='')
84 | print(' | '.join('{: <{}s}'.format(content, lengths[n]) for n, content in enumerate(table[0])), end='')
85 | print(' |')
86 |
87 | print('+', end='')
88 | print('+'.join('=' * (lengths[n] + 2) for n in range(len(table[0]))), end='')
89 | print('+')
90 |
91 |
92 | for row in table[1:]:
93 | print('| {: <{}s} | {: <{}s} | {: <{}s} | {: <{}s} |'.format(row[0], lengths[0],
94 | row[1], lengths[1],
95 | row[2], lengths[2],
96 | row[3], lengths[3]))
97 | print('+', end='')
98 | print('+'.join('-' * (lengths[n] + 2) for n in range(4)), end='')
99 | print('+')
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | crccheck - Classes to calculate CRCs and checksums from binary data
2 | ===================================================================
3 |
4 |
5 | The ``crccheck.crc`` module implements all CRCs listed in the
6 | `Catalogue of parametrised CRC algorithms `_:
7 |
8 | CRC-3/GSM, CRC-3/ROHC, CRC-4/G-704, CRC-4/INTERLAKEN, CRC-5/EPC-C1G2, CRC-5/G-704, CRC-5/USB, CRC-6/CDMA2000-A,
9 | CRC-6/CDMA2000-B, CRC-6/DARC, CRC-6/G-704, CRC-6/GSM, CRC-7/MMC, CRC-7/ROHC, CRC-7/UMTS, CRC-8/AUTOSAR,
10 | CRC-8/BLUETOOTH, CRC-8/CDMA2000, CRC-8/DARC, CRC-8/DVB-S2, CRC-8/GSM-A, CRC-8/GSM-B, CRC-8/HITAG, CRC-8/I-432-1,
11 | CRC-8/I-CODE, CRC-8/LTE, CRC-8/MAXIM-DOW, CRC-8/MIFARE-MAD, CRC-8/NRSC-5, CRC-8/OPENSAFETY, CRC-8/ROHC,
12 | CRC-8/SAE-J1850, CRC-8/SMBUS, CRC-8/TECH-3250, CRC-8/WCDMA, CRC-10/ATM, CRC-10/CDMA2000, CRC-10/GSM, CRC-11/FLEXRAY,
13 | CRC-11/UMTS, CRC-12/CDMA2000, CRC-12/DECT, CRC-12/GSM, CRC-12/UMTS, CRC-13/BBC, CRC-14/DARC, CRC-14/GSM, CRC-15/CAN,
14 | CRC-15/MPT1327, CRC-16/ARC, CRC-16/CDMA2000, CRC-16/CMS, CRC-16/DDS-110, CRC-16/DECT-R, CRC-16/DECT-X, CRC-16/DNP,
15 | CRC-16/EN-13757, CRC-16/GENIBUS, CRC-16/GSM, CRC-16/IBM-3740, CRC-16/IBM-SDLC, CRC-16/ISO-IEC-14443-3-A,
16 | CRC-16/KERMIT, CRC-16/LJ1200, CRC-16/M17, CRC-16/MAXIM-DOW, CRC-16/MCRF4XX, CRC-16/MODBUS, CRC-16/NRSC-5,
17 | CRC-16/OPENSAFETY-A, CRC-16/OPENSAFETY-B, CRC-16/PROFIBUS, CRC-16/RIELLO, CRC-16/SPI-FUJITSU, CRC-16/T10-DIF,
18 | CRC-16/TELEDISK, CRC-16/TMS37157, CRC-16/UMTS, CRC-16/USB, CRC-16/XMODEM, CRC-17/CAN-FD, CRC-21/CAN-FD, CRC-24/BLE,
19 | CRC-24/FLEXRAY-A, CRC-24/FLEXRAY-B, CRC-24/INTERLAKEN, CRC-24/LTE-A, CRC-24/LTE-B, CRC-24/OPENPGP, CRC-24/OS-9,
20 | CRC-30/CDMA, CRC-31/PHILIPS, CRC-32/AIXM, CRC-32/AUTOSAR, CRC-32/BASE91-D, CRC-32/BZIP2, CRC-32/CD-ROM-EDC,
21 | CRC-32/CKSUM, CRC-32/ISCSI, CRC-32/ISO-HDLC, CRC-32/JAMCRC, CRC-32/MEF, CRC-32/MPEG-2, CRC-32/XFER, CRC-40/GSM,
22 | CRC-64/ECMA-182, CRC-64/GO-ISO, CRC-64/MS, CRC-64/NVME, CRC-64/REDIS, CRC-64/WE, CRC-64/XZ, CRC-82/DARC
23 |
24 | For the class names simply remove all dashes and slashes from the above names and apply CamelCase, e.g.
25 | "CRC-32/MPEG-2" is implemented by ``Crc32Mpeg2``. Other CRC can be calculated by using the general class
26 | ``crccheck.crc.Crc`` by providing all required CRC parameters.
27 |
28 | The ``crccheck.checksum`` module implements additive and XOR checksums with 8, 16 and 32 bit:
29 | ``Checksum8``, ``Checksum16``, ``Checksum32`` and ``ChecksumXor8``, ``ChecksumXor16``, ``ChecksumXor32``
30 |
31 | Usage example::
32 |
33 | from crccheck.crc import Crc32, CrcXmodem
34 | from crccheck.checksum import Checksum32
35 |
36 | # Quick calculation
37 | data = bytearray.fromhex("DEADBEEF")
38 | crc = Crc32.calc(data)
39 | checksum = Checksum32.calc(data)
40 |
41 | # Procsss multiple data buffers
42 | data1 = b"Binary string" # or use .encode(..) on normal sring - Python 3 only
43 | data2 = bytes.fromhex("1234567890") # Python 3 only, use bytearray for older versions
44 | data3 = (0x0, 255, 12, 99) # Iterable which returns ints in byte range (0..255)
45 | crcinst = CrcXmodem()
46 | crcinst.process(data1)
47 | crcinst.process(data2)
48 | crcinst.process(data3[1:-1])
49 | crcbytes = crcinst.finalbytes()
50 | crchex = crcinst.finalhex()
51 | crcint = crcinst.final()
52 |
53 |
54 | License:
55 | MIT License
56 |
57 | Copyright (c) 2015-2025 by Martin Scharrer
58 |
59 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
60 | and associated documentation files (the "Software"), to deal in the Software without
61 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
62 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
63 | Software is furnished to do so, subject to the following conditions:
64 |
65 | The above copyright notice and this permission notice shall be included in all copies or
66 | substantial portions of the Software.
67 |
68 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
69 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
70 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
71 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/crccheck/__init__.py:
--------------------------------------------------------------------------------
1 | """ Classes to calculate CRCs and checksums from binary data
2 | ========================================================
3 |
4 | The :mod:`crccheck.crc` module implements all CRCs listed in the
5 | `Catalogue of parametrised CRC algorithms `_:
6 |
7 | CRC-3/GSM, CRC-3/ROHC, CRC-4/G-704, CRC-4/ITU, CRC-4/INTERLAKEN, CRC-5/EPC-C1G2, CRC-5/EPC, CRC-5/G-704, CRC-5/ITU,
8 | CRC-5/USB, CRC-6/CDMA2000-A, CRC-6/CDMA2000-B, CRC-6/DARC, CRC-6/G-704, CRC-6/ITU, CRC-6/GSM, CRC-7/MMC, CRC-7,
9 | CRC-7/ROHC, CRC-7/UMTS, CRC-8/AUTOSAR, CRC-8/BLUETOOTH, CRC-8/CDMA2000, CRC-8/DARC, CRC-8/DVB-S2, CRC-8/GSM-A,
10 | CRC-8/GSM-B, CRC-8/I-432-1, CRC-8/ITU, CRC-8/I-CODE, CRC-8/LTE, CRC-8/MAXIM-DOW, CRC-8/MAXIM, DOW-CRC,
11 | CRC-8/MIFARE-MAD, CRC-8/NRSC-5, CRC-8/OPENSAFETY, CRC-8/ROHC, CRC-8/SAE-J1850, CRC-8/SMBUS, CRC-8, CRC-8/TECH-3250,
12 | CRC-8/AES, CRC-8/EBU, CRC-8/WCDMA, CRC-10/ATM, CRC-10, CRC-10/I-610, CRC-10/CDMA2000, CRC-10/GSM, CRC-11/FLEXRAY,
13 | CRC-11, CRC-11/UMTS, CRC-12/CDMA2000, CRC-12/DECT, CRC-12-X, CRC-12/GSM, CRC-12/UMTS, CRC-12/3GPP, CRC-13/BBC,
14 | CRC-14/DARC, CRC-14/GSM, CRC-15/CAN, CRC-15, CRC-15/MPT1327, CRC-16/ARC, ARC, CRC-16/LHA, CRC-IBM, CRC-16/CDMA2000,
15 | CRC-16/CMS, CRC-16/DDS-110, CRC-16/DECT-R, R-CRC-16, CRC-16/DECT-X, X-CRC-16, CRC-16/DNP, CRC-16/EN-13757,
16 | CRC-16/GENIBUS, CRC-16/DARC, CRC-16/EPC, CRC-16/EPC-C1G2, CRC-16/I-CODE, CRC-16/GSM, CRC-16/IBM-3740,
17 | CRC-16/AUTOSAR, CRC-16/CCITT-FALSE, CRC-16/IBM-SDLC, CRC-16/ISO-HDLC, CRC-16/ISO-IEC-14443-3-B, CRC-16/X-25, CRC-B,
18 | X-25, CRC-16/ISO-IEC-14443-3-A, CRC-A, CRC-16/KERMIT, CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/V-41-LSB, CRC-CCITT,
19 | KERMIT, CRC-16/LJ1200, CRC-16/MAXIM-DOW, CRC-16/MAXIM, CRC-16/MCRF4XX, CRC-16/MODBUS, MODBUS, CRC-16/NRSC-5,
20 | CRC-16/OPENSAFETY-A, CRC-16/OPENSAFETY-B, CRC-16/PROFIBUS, CRC-16/IEC-61158-2, CRC-16/RIELLO, CRC-16/SPI-FUJITSU,
21 | CRC-16/AUG-CCITT, CRC-16/T10-DIF, CRC-16/TELEDISK, CRC-16/TMS37157, CRC-16/UMTS, CRC-16/BUYPASS, CRC-16/VERIFONE,
22 | CRC-16/USB, CRC-16/XMODEM, CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM, CRC-17/CAN-FD, CRC-21/CAN-FD,
23 | CRC-24/BLE, CRC-24/FLEXRAY-A, CRC-24/FLEXRAY-B, CRC-24/INTERLAKEN, CRC-24/LTE-A, CRC-24/LTE-B, CRC-24/OPENPGP,
24 | CRC-24, CRC-24/OS-9, CRC-30/CDMA, CRC-31/PHILIPS, CRC-32/AIXM, CRC-32Q, CRC-32/AUTOSAR, CRC-32/BASE91-D, CRC-32D,
25 | CRC-32/BZIP2, CRC-32/AAL5, CRC-32/DECT-B, B-CRC-32, CRC-32/CD-ROM-EDC, CRC-32/CKSUM, CKSUM, CRC-32/POSIX,
26 | CRC-32/ISCSI, CRC-32/BASE91-C, CRC-32/CASTAGNOLI, CRC-32/INTERLAKEN, CRC-32C, CRC-32/ISO-HDLC, CRC-32,
27 | CRC-32/ADCCP, CRC-32/V-42, CRC-32/XZ, PKZIP, CRC-32/JAMCRC, JAMCRC, CRC-32/MPEG-2, CRC-32/XFER, XFER, CRC-40/GSM,
28 | CRC-64/ECMA-182, CRC-64, CRC-64/GO-ISO, CRC-64/WE, CRC-64/XZ, CRC-64/GO-ECMA, CRC-82/DARC.
29 |
30 | For the class names simply remove all dashes and slashes from the above names and apply CamelCase, e.g.
31 | "CRC-32/MPEG-2" is implemented by :class:`.Crc32Mpeg2`. Other CRC can be calculated by using the general class
32 | :class:`crccheck.crc.Crc` by providing all required CRC parameters.
33 |
34 | The :mod:`crccheck.checksum` module implements additive and XOR checksums with 8, 16 and 32 bit:
35 | :class:`.Checksum8`, :class:`.Checksum16`, :class:`.Checksum32` and
36 | :class:`.ChecksumXor8`, :class:`.ChecksumXor16`, :class:`.ChecksumXor32`.
37 |
38 | Usage example::
39 |
40 | from crccheck.crc import Crc32, CrcXmodem
41 | from crccheck.checksum import Checksum32
42 |
43 | # Quick calculation
44 | data = bytearray.fromhex("DEADBEEF")
45 | crc = Crc32.calc(data)
46 | checksum = Checksum32.calc(data)
47 |
48 | # Procsss multiple data buffers
49 | data1 = b"Binary string" # or use .encode(..) on normal sring - Python 3 only
50 | data2 = bytes.fromhex("1234567890") # Python 3 only, use bytearray for older versions
51 | data3 = (0x0, 255, 12, 99) # Iterable which returns ints in byte range (0..255)
52 | crcinst = CrcXmodem()
53 | crcinst.process(data1)
54 | crcinst.process(data2)
55 | crcinst.process(data3[1:-1])
56 | crcbytes = crcinst.finalbytes()
57 | crchex = crcinst.finalhex()
58 | crcint = crcinst.final()
59 |
60 | License:
61 | MIT License
62 |
63 | Copyright (c) 2015-2022 by Martin Scharrer
64 |
65 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
66 | and associated documentation files (the "Software"), to deal in the Software without
67 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
68 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
69 | Software is furnished to do so, subject to the following conditions:
70 |
71 | The above copyright notice and this permission notice shall be included in all copies or
72 | substantial portions of the Software.
73 |
74 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
75 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
76 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
77 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
79 |
80 | """
81 | from crccheck import crc, checksum
82 |
--------------------------------------------------------------------------------
/tests/test_checksum.py:
--------------------------------------------------------------------------------
1 | """ Unit tests for checksum module.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | import sys
26 |
27 | from crccheck import checksum
28 | from crccheck.base import CrccheckError
29 | from crccheck.checksum import ALLCHECKSUMCLASSES, Checksum32, Checksum, ChecksumXor
30 | from tests import TestCase, randbytes
31 |
32 |
33 | class TestChecksum(TestCase):
34 |
35 | def test_allchecksums_bigendian(self):
36 | for checksumclass in ALLCHECKSUMCLASSES:
37 | with self.subTest(checksumclass=checksumclass):
38 | checksumclass.selftest(byteorder='big')
39 |
40 | def test_allchecksums_littleendian(self):
41 | for checksumclass in ALLCHECKSUMCLASSES:
42 | with self.subTest(checksumclass=checksumclass):
43 | checksumclass.selftest(byteorder='little')
44 |
45 | # noinspection PyProtectedMember
46 | def test_allchecksums_fail(self):
47 | with self.assertRaises(CrccheckError):
48 | checksumclass = ALLCHECKSUMCLASSES[0]
49 | checksumclass.selftest(checksumclass._check_data, ~checksumclass._check_result)
50 |
51 | def test_generator(self):
52 | Checksum32.calc((n for n in range(0, 255)))
53 |
54 | def test_list1(self):
55 | Checksum32.calc([n for n in range(0, 255)])
56 |
57 | def test_list2(self):
58 | Checksum32.calc([n for n in range(0, 255)], 1)
59 |
60 | def test_bytearray1(self):
61 | Checksum32.calc(bytearray.fromhex("12345678909876543210"))
62 |
63 | def test_bytes(self):
64 | if sys.version_info < (3, 3, 0): # pragma: no cover
65 | raise self.skipTest("")
66 | Checksum32.calc(bytes.fromhex("12345678909876543210"))
67 |
68 | def test_string1(self):
69 | if sys.version_info < (3, 3, 0): # pragma: no cover
70 | raise self.skipTest("")
71 | Checksum32.calc(b"Teststring")
72 |
73 | def test_string3(self):
74 | if sys.version_info < (3, 3, 0): # pragma: no cover
75 | raise self.skipTest("")
76 | Checksum32.calc("Teststring".encode(), )
77 |
78 | def test_general_checksum_valid_width(self):
79 | """ Checksum()
80 |
81 | Should allow for any positive width
82 | which is a multiple of 8.
83 | """
84 | for n in range(8, 129, 8):
85 | Checksum(n)
86 |
87 | def test_general_checksum_invalid_width(self):
88 | for n in (0, 1, 7, 9, 33):
89 | with self.assertRaises(ValueError):
90 | Checksum(n)
91 |
92 | def test_general_checksum_ident(self):
93 | data = randbytes(1024)
94 | self.assertEqual(checksum.Checksum32.calc(data), checksum.Checksum(32).process(data).final())
95 | self.assertEqual(checksum.Checksum16.calc(data), checksum.Checksum(16).process(data).final())
96 | self.assertEqual(checksum.Checksum8.calc(data), checksum.Checksum(8).process(data).final())
97 |
98 | def test_general_checksumxor_valid_width(self):
99 | """ Checksum()
100 |
101 | Should allow for any positive width
102 | which is a multiple of 8.
103 | """
104 | for n in range(8, 129, 8):
105 | ChecksumXor(n)
106 |
107 | def test_general_checksumxor_invalid_width(self):
108 | for n in (0, 1, 7, 9, 33):
109 | with self.assertRaises(ValueError):
110 | ChecksumXor(n)
111 |
112 | def test_general_checksumxor_ident(self):
113 | data = randbytes(1024)
114 | self.assertEqual(checksum.ChecksumXor32.calc(data), checksum.ChecksumXor(32).process(data).final())
115 | self.assertEqual(checksum.ChecksumXor16.calc(data), checksum.ChecksumXor(16).process(data).final())
116 | self.assertEqual(checksum.ChecksumXor8.calc(data), checksum.ChecksumXor(8).process(data).final())
117 |
118 | def test_getter(self):
119 | """Test if all getter return the underlying value correctly."""
120 | for cls in ALLCHECKSUMCLASSES:
121 | for clsorinst in (cls, cls()):
122 | with self.subTest(clsorinst=clsorinst, attr='mask'):
123 | self.assertEqual(clsorinst.mask(), clsorinst._mask)
124 | with self.subTest(clsorinst=clsorinst, attr='check_result'):
125 | self.assertEqual(clsorinst.check_result(), clsorinst._check_result)
126 | self.assertEqual(clsorinst.check_result(byteorder='big'), clsorinst._check_result)
127 | self.assertEqual(clsorinst.check_result(byteorder='little'), clsorinst._check_result_littleendian)
128 |
--------------------------------------------------------------------------------
/crccheck/__main__.py:
--------------------------------------------------------------------------------
1 | """ crccheck main function.
2 |
3 | License:
4 | MIT License
5 |
6 | Copyright (c) 2015-2022 by Martin Scharrer
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9 | and associated documentation files (the "Software"), to deal in the Software without
10 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
11 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
12 | Software is furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all copies or
15 | substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 |
23 | """
24 | import sys
25 |
26 | from crccheck import crc, checksum, base
27 |
28 |
29 | def usage():
30 | """crccheck command line interface:
31 |
32 | Usage: python -m crccheck CrcOrChecksumClassName [-H|-h|-B|-b|-D|-d] [inputfile|-] [outputfile|-].
33 |
34 | CrcOrChecksumClassName: A class name of crccheck.crc or crccheck.checksum, e.g. Crc32.
35 | inputfile: Name of file to calculate CRC/checksum over. If '-' then data is read from standard input.
36 | outputfile: Name of file to write result to. If '-' or missing then result is written to standard output.
37 | -B: Result in bytes: big endian
38 | -b: Result in bytes: little endian
39 | -h: Result in hexadecimal.
40 | -H: Result in hexadecimal with leading 0x. (default)
41 | -d|-D: Result in decimal.
42 | """
43 | print(usage.__doc__)
44 |
45 |
46 | def getgenericcrccls(clsstr: str):
47 | clsstr = clsstr.strip()
48 | if not clsstr.startswith('Crc(') or not clsstr.endswith(')'):
49 | raise ValueError('Invalid generic CRC specification!')
50 | clsstr = clsstr[4:-1]
51 | allargs = [arg.strip() for arg in clsstr.split(',')]
52 | kwargs = dict()
53 | args = list()
54 | for arg in allargs:
55 | if '=' in arg:
56 | k, v = arg.split('=', 1)
57 | kwargs[k.rstrip()] = v.lstrip()
58 | else:
59 | args.append(arg)
60 | try:
61 | return crc.crccls(*args, **kwargs)
62 | except (AttributeError, ValueError):
63 | raise ValueError("Invalid generic CRC specification!")
64 |
65 |
66 | def getcls(clsname):
67 | """Get CRC/checksum class by name."""
68 | if clsname.startswith('Crc('):
69 | return getgenericcrccls(clsname)
70 | for mod in (crc, checksum):
71 | try:
72 | cls = getattr(mod, clsname)
73 | if not issubclass(cls, base.CrccheckBase):
74 | raise ValueError("Invalid class name!")
75 | return cls
76 | except AttributeError:
77 | continue
78 | except ValueError:
79 | raise
80 | raise ValueError("Unknown class name!")
81 |
82 |
83 | def calcfh(crcinst, fh, blocksize=16 * 1024 * 1024):
84 | while True:
85 | data = fh.read(blocksize)
86 | if not data:
87 | break
88 | crcinst.process(data)
89 |
90 |
91 | def main(args):
92 | args = list(args)
93 | try:
94 | clsname = args.pop(0)
95 | resultformat = args.pop(0) if args else '-'
96 | if not (len(resultformat) == 2 and resultformat[0] == '-'):
97 | infilename = resultformat
98 | resultformat = 'H'
99 | else:
100 | infilename = args.pop(0) if args else '-'
101 | resultformat = resultformat[1]
102 | if resultformat not in 'hHbBdD':
103 | raise ValueError("Invalid option -{:s}!".format(resultformat))
104 | outfilename = args.pop(0) if args else '-'
105 | isbinaryoutput = (resultformat.lower() == 'b')
106 | cls = getcls(clsname)
107 |
108 | crcinst = cls()
109 | if infilename == '-':
110 | calcfh(crcinst, sys.stdin.buffer)
111 | else:
112 | with open(infilename, "rb") as fh:
113 | calcfh(crcinst, fh)
114 | if resultformat.lower() == 'h':
115 | result = crcinst.finalhex().upper()
116 | if resultformat == 'H':
117 | result = '0x' + result
118 | elif resultformat == 'd':
119 | result = crcinst.final()
120 | elif resultformat == 'b':
121 | result = crcinst.finalbytes('little')
122 | elif resultformat == 'B':
123 | result = crcinst.finalbytes('big')
124 | else:
125 | raise ValueError
126 |
127 | if outfilename == '-':
128 | if isbinaryoutput:
129 | sys.stdout.buffer.write(result)
130 | else:
131 | print(str(result))
132 | else:
133 | mode = 'wb' if isbinaryoutput else 'w'
134 | with open(outfilename, mode) as fh:
135 | fh.write(result)
136 | if not isbinaryoutput:
137 | fh.write('\n')
138 |
139 | except IndexError:
140 | print("Invalid number of arguments.")
141 | usage()
142 | except ValueError as e:
143 | print("Invalid argument values: " + str(e))
144 | usage()
145 |
146 |
147 | if __name__ == '__main__':
148 | main(sys.argv[1:])
149 |
--------------------------------------------------------------------------------
/tests/test_base.py:
--------------------------------------------------------------------------------
1 | """Test modules for base package.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | import random
26 | import sys
27 |
28 | from crccheck.base import CrccheckBase
29 | from crccheck.checksum import ALLCHECKSUMCLASSES
30 | from crccheck.crc import ALLCRCCLASSES, ALLCRCCLASSES_ALIASES
31 | from tests import TestCase, randbytes
32 |
33 |
34 | class TestBase(TestCase):
35 |
36 | def test_abstract_method(self):
37 | """ For coverage """
38 | with self.assertRaises(NotImplementedError):
39 | ab = CrccheckBase()
40 | ab.process(bytearray(10))
41 |
42 | def test_init(self):
43 | for CrcClass in ALLCRCCLASSES:
44 | with self.subTest(CrcClass):
45 | for n in range(0, 16):
46 | value = random.randint(0, 4294967295)
47 | self.assertEqual(CrcClass(value).value(), value)
48 |
49 | def test_reset(self):
50 | for CrcClass in ALLCRCCLASSES:
51 | with self.subTest(CrcClass):
52 | for n in range(0, 16):
53 | value = random.randint(0, 4294967295)
54 | c = CrcClass()
55 | c.reset(value)
56 | self.assertEqual(c.value(), value)
57 |
58 | def test_final(self):
59 | """.final() should not change internal value"""
60 | for CrcClass in ALLCRCCLASSES:
61 | with self.subTest(CrcClass):
62 | for n in range(0, 16):
63 | data = randbytes(16)
64 | crc = CrcClass()
65 | crc.process(data)
66 | self.assertEqual(crc.final(), crc.final())
67 |
68 | def test_finalhex(self):
69 | """.finalhex() should match .final()"""
70 | for CrcClass in ALLCRCCLASSES:
71 | with self.subTest(CrcClass):
72 | for n in range(0, 16):
73 | data = randbytes(16)
74 | crc = CrcClass()
75 | crc.process(data)
76 | self.assertEqual(crc.final(), int(crc.finalhex(), 16))
77 |
78 | def test_finalbytes_big(self):
79 | """.finalbytes() should match .final()"""
80 | if sys.version_info < (3, 3, 0): # pragma: no cover
81 | raise self.skipTest("")
82 | for CrcClass in ALLCRCCLASSES:
83 | with self.subTest(CrcClass):
84 | for n in range(0, 16):
85 | data = randbytes(16)
86 | crc = CrcClass()
87 | crc.process(data)
88 | self.assertEqual(crc.final(), int.from_bytes(crc.finalbytes('big'), 'big'))
89 |
90 | def test_finalbytes_little(self):
91 | """.finalbytes() should match .final()"""
92 | if sys.version_info < (3, 3, 0): # pragma: no cover
93 | raise self.skipTest("")
94 | for CrcClass in ALLCRCCLASSES:
95 | with self.subTest(CrcClass):
96 | for n in range(0, 16):
97 | data = randbytes(16)
98 | crc = CrcClass()
99 | crc.process(data)
100 | self.assertEqual(crc.final(), int.from_bytes(crc.finalbytes('little'), 'little'))
101 |
102 | def test_calc(self):
103 | """.calc() must be identical to .process() + .final()"""
104 | for CrcClass in ALLCRCCLASSES:
105 | with self.subTest(CrcClass):
106 | for n in range(0, 16):
107 | data = randbytes(16)
108 | crc = CrcClass()
109 | crc.process(data)
110 | self.assertEqual(CrcClass.calc(data), crc.final())
111 |
112 | def test_calchex_big(self):
113 | """.calchex() must be identical to .process() + .finalhex()"""
114 | for CrcClass in ALLCRCCLASSES:
115 | with self.subTest(CrcClass):
116 | for n in range(0, 16):
117 | data = randbytes(16)
118 | crc = CrcClass()
119 | crc.process(data)
120 | self.assertEqual(CrcClass.calchex(data, byteorder='big'), crc.finalhex('big'))
121 |
122 | def test_calchex_little(self):
123 | """.calchex() must be identical to .process() + .finalhex()"""
124 | for CrcClass in ALLCRCCLASSES:
125 | with self.subTest(CrcClass):
126 | for n in range(0, 16):
127 | data = randbytes(16)
128 | crc = CrcClass()
129 | crc.process(data)
130 | self.assertEqual(CrcClass.calchex(data, byteorder='little'), crc.finalhex('little'))
131 |
132 | def test_calcbytes_big(self):
133 | """.calcbytes() must be identical to .process() + .finalbytes()"""
134 | for CrcClass in ALLCRCCLASSES:
135 | with self.subTest(CrcClass):
136 | for n in range(0, 16):
137 | data = randbytes(16)
138 | crc = CrcClass()
139 | crc.process(data)
140 | self.assertSequenceEqual(CrcClass.calcbytes(data, byteorder='big'), crc.finalbytes('big'))
141 |
142 | def test_calcbytes_little(self):
143 | """.calcbytes() must be identical to .process() + .finalbytes()"""
144 | for CrcClass in ALLCRCCLASSES:
145 | with self.subTest(CrcClass):
146 | for n in range(0, 16):
147 | data = randbytes(16)
148 | crc = CrcClass()
149 | crc.process(data)
150 | self.assertSequenceEqual(CrcClass.calcbytes(data, byteorder='little'), crc.finalbytes('little'))
151 |
152 | def test_getter(self):
153 | """Test if all getter return the underlying value correctly."""
154 | for cls in ALLCRCCLASSES_ALIASES + ALLCHECKSUMCLASSES:
155 | for attr in ("initvalue", "check_result", "check_data", "width"):
156 | for clsorinst in (cls, cls()):
157 | # x.foo() should return x._foo
158 | with self.subTest(clsorinst=clsorinst, attr=attr):
159 | self.assertEqual(getattr(clsorinst, attr)(), getattr(clsorinst, "_" + attr))
160 | # Except x.bytewidth() as it returns a value based on x._width
161 | with self.subTest(clsorinst=clsorinst, attr='bytewidth'):
162 | self.assertGreaterEqual(clsorinst.bytewidth() * 8, getattr(clsorinst, "_width"))
163 |
--------------------------------------------------------------------------------
/create/dl.py:
--------------------------------------------------------------------------------
1 | import urllib.request
2 | import re
3 | import sys
4 |
5 | renames = {
6 | 'ARC': 'CrcArc',
7 | 'DOW-CRC': 'CrcDow',
8 | 'R-CRC-16': 'Crc16R',
9 | 'X-CRC-16': 'Crc16X',
10 | 'X-25': 'CrcX25',
11 | 'KERMIT': 'CrcKermit',
12 | 'MODBUS': 'CrcModbus',
13 | 'XMODEM': 'CrcXmodem',
14 | 'ZMODEM': 'CrcZmodem',
15 | 'B-CRC-32': 'Crc32B',
16 | 'CKSUM': 'CrcCksum',
17 | 'PKZIP': 'CrcPkzip',
18 | 'JAMCRC': 'CrcJamcrc',
19 | 'XFER': 'CrcXfer',
20 | }
21 |
22 | aliases = {
23 | 'CRC-4/G-704': ('CRC-4/ITU',),
24 | 'CRC-5/EPC-C1G2': ('CRC-5/EPC',),
25 | 'CRC-5/G-704': ('CRC-5/ITU',),
26 | 'CRC-6/G-704': ('CRC-6/ITU',),
27 | 'CRC-7/MMC': ('CRC-7',),
28 | 'CRC-8/I-432-1': ('CRC-8/ITU',),
29 | 'CRC-8/MAXIM-DOW': ('CRC-8/MAXIM', 'DOW-CRC'),
30 | 'CRC-8/SMBUS': ('CRC-8',),
31 | 'CRC-8/TECH-3250': ('CRC-8/AES', 'CRC-8/EBU'),
32 | 'CRC-10/ATM': ('CRC-10', 'CRC-10/I-610'),
33 | 'CRC-11/FLEXRAY': ('CRC-11',),
34 | 'CRC-12/DECT': ('CRC-12-X',),
35 | 'CRC-12/UMTS': ('CRC-12/3GPP',),
36 | 'CRC-15/CAN': ('CRC-15',),
37 | 'CRC-16/ARC': ('ARC', 'CRC-16/LHA', 'CRC-IBM'), # Crc16, but not used for backward compatibility
38 | 'CRC-16/DECT-R': ('R-CRC-16',),
39 | 'CRC-16/DECT-X': ('X-CRC-16',),
40 | 'CRC-16/GENIBUS': ('CRC-16/DARC', 'CRC-16/EPC', 'CRC-16/EPC-C1G2', 'CRC-16/I-CODE'),
41 | 'CRC-16/IBM-3740': ('CRC-16/AUTOSAR', 'CRC-16/CCITT-FALSE'),
42 | 'CRC-16/IBM-SDLC': ('CRC-16/ISO-HDLC', 'CRC-16/ISO-IEC-14443-3-B', 'CRC-16/X-25', 'CRC-B', 'X-25'),
43 | 'CRC-16/ISO-IEC-14443-3-A': ('CRC-A',),
44 | 'CRC-16/KERMIT': ('CRC-16/CCITT', 'CRC-16/CCITT-TRUE', 'CRC-16/V-41-LSB', 'CRC-CCITT', 'KERMIT'),
45 | 'CRC-16/MAXIM-DOW': ('CRC-16/MAXIM',),
46 | 'CRC-16/MODBUS': ('MODBUS',),
47 | 'CRC-16/PROFIBUS': ('CRC-16/IEC-61158-2',),
48 | 'CRC-16/SPI-FUJITSU': ('CRC-16/AUG-CCITT',),
49 | 'CRC-16/UMTS': ('CRC-16/BUYPASS', 'CRC-16/VERIFONE'),
50 | 'CRC-16/XMODEM': ('CRC-16/ACORN', 'CRC-16/LTE', 'CRC-16/V-41-MSB', 'XMODEM', 'ZMODEM'), # Crc16 only for backward compatibility
51 | 'CRC-24/OPENPGP': ('CRC-24',),
52 | 'CRC-32/AIXM': ('CRC-32Q',),
53 | 'CRC-32/BASE91-D': ('CRC-32D',),
54 | 'CRC-32/BZIP2': ('CRC-32/AAL5', 'CRC-32/DECT-B', 'B-CRC-32'),
55 | 'CRC-32/CKSUM': ('CKSUM', 'CRC-32/POSIX'),
56 | 'CRC-32/ISCSI': ('CRC-32/BASE91-C', 'CRC-32/CASTAGNOLI', 'CRC-32/INTERLAKEN', 'CRC-32C'),
57 | 'CRC-32/ISO-HDLC': ('CRC-32', 'CRC-32/ADCCP', 'CRC-32/V-42', 'CRC-32/XZ', 'PKZIP'),
58 | 'CRC-32/JAMCRC': ('JAMCRC',),
59 | 'CRC-32/XFER': ('XFER',),
60 | 'CRC-64/ECMA-182': ('CRC-64', ),
61 | 'CRC-64/XZ': ('CRC-64/GO-ECMA',),
62 | }
63 |
64 | extra_class_aliases = {
65 | 'CRC-16/MCRF4XX': ('Crc16Mcrf4XX', 'Crcc16Mcrf4xx'),
66 | 'CRC-24/OPENPGP': ('Crc24OpenPgp',),
67 | 'CRC-32/AIXM': ('Crc32q',),
68 | 'CRC-32/BASE91-D': ('Crc32d',),
69 | 'CRC-32/ISCSI': ('Crc32c',),
70 | 'CRC-16/XMODEM': ('Crc16',)
71 | }
72 |
73 | rCRC = re.compile(r'\s+'.join((
74 | r'width=(\d+)',
75 | r'poly=0x([0-9a-fA-F]+)',
76 | r'init=0x([0-9a-fA-F]+)',
77 | r'refin=(\S+)',
78 | r'refout=(\S+)',
79 | r'xorout=0x([0-9a-fA-F]+)',
80 | r'check=0x([0-9a-fA-F]+)',
81 | r'residue=0x([0-9a-fA-F]+)',
82 | r'name="([^"]*)"',
83 | )))
84 |
85 | template = """
86 | class {10}({9}):
87 | \"\"\"{8}{11}\"\"\"
88 | _names = ({12})
89 | _width = {0}
90 | _poly = 0x{1}
91 | _initvalue = 0x{2}
92 | _reflect_input = {3}
93 | _reflect_output = {4}
94 | _xor_output = 0x{5}
95 | _check_result = 0x{6}
96 | _residue = 0x{7}
97 |
98 | """
99 |
100 | urls = (
101 | r'https://reveng.sourceforge.io/crc-catalogue/1-15.htm',
102 | r'https://reveng.sourceforge.io/crc-catalogue/16.htm',
103 | r'https://reveng.sourceforge.io/crc-catalogue/17plus.htm',
104 | )
105 |
106 |
107 | class OutFile(object):
108 | def __init__(self, argv, idx):
109 | try:
110 | fname = argv[idx]
111 | except IndexError:
112 | fname = '-'
113 | if fname == '-':
114 | self.fhandle = sys.stdout
115 | else:
116 | self.fhandle = open(fname, 'w')
117 |
118 | def __enter__(self):
119 | return self.fhandle
120 |
121 | def __exit__(self, type, value, traceback):
122 | if self.fhandle is not sys.stdout:
123 | self.fhandle.close()
124 |
125 |
126 | def linejoin(line, length, indent):
127 | lines = []
128 | maxlen = length - len(indent)
129 | try:
130 | while len(line) > maxlen:
131 | idx = line.rindex(', ', 0, maxlen)
132 | lines.append(indent + line[0:idx+1] + '\n')
133 | line = line[idx+2:]
134 | except ValueError:
135 | pass
136 | lines.append(indent + line + '\n') # append rest
137 | return lines
138 |
139 |
140 | def getclassname(strname):
141 | if strname in renames:
142 | return renames[strname]
143 | return strname.replace('-', ' ').replace('/', ' ').title().replace(' ', '')
144 |
145 |
146 | def getbaseclass(width):
147 | return {8: 'Crc8Base', 16: 'Crc16Base', 32: 'Crc32Base'}.get(int(width), 'CrcBase')
148 |
149 |
150 | if __name__ == "__main__":
151 |
152 | crcs = list()
153 |
154 | with open('../crccheck/crc.py', 'r') as infh:
155 | crchead = infh.readlines()
156 |
157 | try:
158 | marker = "# # # CRC CLASSES # # #\n"
159 | crchead = crchead[:crchead.index(marker)+1]
160 | except ValueError:
161 | pass
162 |
163 | for url in urls:
164 | response = urllib.request.urlopen(url)
165 | data = response.read().decode('utf-8')
166 | for crc in rCRC.findall(data):
167 | crc = list(crc)
168 | crc[3] = crc[3].capitalize()
169 | crc[4] = crc[4].capitalize()
170 | crc.append(getbaseclass(crc[0]))
171 | crc.append(getclassname(crc[8]))
172 | crcs.append(crc)
173 |
174 | crcs.sort(key=lambda x: (int(x[0]), x[10]))
175 |
176 | with OutFile(sys.argv, 1) as outfh:
177 | crcallaliases = []
178 |
179 | outfh.writelines(crchead)
180 | outfh.write('\n')
181 |
182 | for crc in crcs:
183 | name = crc[8]
184 | clsname = crc[10]
185 | othernames = aliases.get(name, ())
186 |
187 | if othernames:
188 | aliasdoc = '\n\n Aliases: ' + (', '.join(othernames)) + '\n '
189 | namelist = [name]
190 | namelist.extend(othernames)
191 | names = "'" + ("', '".join(namelist)) + "'"
192 | else:
193 | aliasdoc = ''
194 | names = "'" + name + "',"
195 |
196 | outfh.write(template.format(*crc, aliasdoc, names))
197 | crcallaliases.append(clsname)
198 |
199 | if name in aliases:
200 | outfh.write('\n')
201 | for alias in aliases.get(name, ()):
202 | clsalias = getclassname(alias)
203 | outfh.write('{} = {}\n'.format(clsalias, clsname))
204 | crcallaliases.append(clsalias)
205 | if name in extra_class_aliases:
206 | if name not in aliases:
207 | outfh.write('\n')
208 | for clsalias in extra_class_aliases.get(name, ()):
209 | outfh.write('{} = {}\n'.format(clsalias, clsname))
210 | crcallaliases.append(clsalias)
211 | if name in aliases or name in extra_class_aliases:
212 | outfh.write('\n')
213 |
214 | allcls = ", ".join(crc[10] for crc in crcs)
215 | lines = ['\n', 'ALLCRCCLASSES = (\n']
216 | lines.extend(linejoin(allcls, 120, ' ' * 4))
217 | lines.append(')\n')
218 |
219 | allclsalias = ", ".join(crcallaliases)
220 | lines.extend(['\n', 'ALLCRCCLASSES_ALIASES = (\n'])
221 | lines.extend(linejoin(allclsalias, 120, ' ' * 4))
222 | lines.append(')\n')
223 |
224 | for line in lines:
225 | outfh.write(line)
226 |
--------------------------------------------------------------------------------
/crccheck/checksum.py:
--------------------------------------------------------------------------------
1 | """ Classes to calculated additive and XOR checksums.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | from crccheck.base import CrccheckBase, CrccheckError
26 |
27 |
28 | class ChecksumBase(CrccheckBase):
29 | """ Base class for all checksum classes.
30 |
31 | Args:
32 | initvalue (int): Initial value. If None then the default value for the class is used.
33 | byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes.
34 | """
35 | _width = 0
36 | _mask = 0
37 | _check_data = (0xDE, 0xAD, 0xBE, 0xEF, 0xAA, 0x55, 0xC2, 0x8C)
38 | _check_result_littleendian = None
39 |
40 | def __init__(self, initvalue=0, byteorder='big'):
41 | super(ChecksumBase, self).__init__(initvalue)
42 | self._byteorder = byteorder
43 |
44 | @classmethod
45 | def mask(cls):
46 | """Getter for mask."""
47 | return cls._mask
48 |
49 | @classmethod
50 | def check_result(cls, byteorder='big'):
51 | """
52 | Getter for check_result.
53 | Args:
54 | byteorder: Either 'big' (default) or 'little'.
55 | Should only be used as a keyword argument for upwards compatiblity.
56 | """
57 | if byteorder == 'big':
58 | return cls._check_result
59 | else:
60 | return cls._check_result_littleendian
61 |
62 | def process(self, data):
63 | """ Process given data.
64 |
65 | Args:
66 | data (bytes, bytearray or list of ints [0-255]): input data to process.
67 |
68 | Returns:
69 | self
70 | """
71 | dataword = 0
72 | n = 0
73 | bigendian = (self._byteorder == 'big')
74 | width = self._width
75 | mask = self._mask
76 | value = self._value
77 | for byte in data:
78 | if bigendian:
79 | dataword = (dataword << 8) | byte
80 | else:
81 | dataword |= (byte << n)
82 | n += 8
83 | if n == width:
84 | value = mask & (value + dataword)
85 | dataword = 0
86 | n = 0
87 | self._value = value
88 | return self
89 |
90 | @classmethod
91 | def selftest(cls, data=None, expectedresult=None, byteorder='big'):
92 | """ Selftest method for automated tests.
93 |
94 | Args:
95 | data (bytes, bytearray or list of int [0-255]): data to process
96 | expectedresult (int): expected result
97 | byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes.
98 |
99 | Raises:
100 | CrccheckError: if result is not as expected
101 | """
102 | if data is None:
103 | data = cls._check_data
104 | if expectedresult is None:
105 | if byteorder == 'big':
106 | expectedresult = cls._check_result
107 | else:
108 | expectedresult = cls._check_result_littleendian
109 | result = cls.calc(data, byteorder=byteorder)
110 | if result != expectedresult:
111 | raise CrccheckError(hex(result))
112 |
113 |
114 | class Checksum32(ChecksumBase):
115 | """ 32-bit checksum.
116 |
117 | Calculates 32-bit checksum by adding the input bytes in groups of four.
118 | Input data length must be a multiple of four, otherwise the last bytes are not used.
119 | """
120 | _width = 32
121 | _mask = 0xFFffFFff
122 | _check_result = 0x8903817B
123 | _check_result_littleendian = 0x7C810388
124 |
125 |
126 | class Checksum16(ChecksumBase):
127 | """ 16-bit checksum.
128 |
129 | Calculates 16-bit checksum by adding the input bytes in groups of two.
130 | Input data length must be a multiple of two, otherwise the last byte is not used.
131 | """
132 | _width = 16
133 | _mask = 0xFFff
134 | _check_result = 0x0A7D
135 | _check_result_littleendian = 0x8008
136 |
137 |
138 | class Checksum8(ChecksumBase):
139 | """ 8-bit checksum.
140 |
141 | Calculates 8-bit checksum by adding the input bytes.
142 | """
143 | _width = 8
144 | _mask = 0xFF
145 | _check_result = 0x85
146 | _check_result_littleendian = _check_result
147 |
148 |
149 | class ChecksumXorBase(ChecksumBase):
150 | """ Base class for all XOR checksum classes. """
151 |
152 | def process(self, data):
153 | """ Process given data.
154 |
155 | Args:
156 | data (bytes, bytearray or list of ints [0-255]): input data to process.
157 |
158 | Returns:
159 | self
160 | """
161 | dataword = 0
162 | n = 0
163 | bigendian = (self._byteorder == 'big')
164 | width = self._width
165 | mask = self._mask
166 | value = self._value
167 | for byte in data:
168 | if bigendian:
169 | dataword = (dataword << 8) | byte
170 | else:
171 | dataword |= (byte << n)
172 | n += 8
173 | if n == width:
174 | value = mask & (value ^ dataword)
175 | dataword = 0
176 | n = 0
177 | self._value = value
178 | return self
179 |
180 |
181 | class ChecksumXor32(ChecksumXorBase):
182 | """ 32-bit XOR checksum.
183 |
184 | Calculates 32-bit checksum by XOR-ing the input bytes in groups of four.
185 | Input data length must be a multiple of four, otherwise the last bytes are not used.
186 | """
187 | _width = 32
188 | _mask = 0xFFffFFff
189 | _check_result = 0x74F87C63
190 | _check_result_littleendian = 0x637CF874
191 |
192 |
193 | class ChecksumXor16(ChecksumXorBase):
194 | """ 16-bit XOR checksum.
195 |
196 | Calculates 16-bit checksum by XOR-ing the input bytes in groups of two.
197 | Input data length must be a multiple of two, otherwise the last byte is not used.
198 | """
199 | _width = 16
200 | _mask = 0xFFff
201 | _check_result = 0x089B
202 | _check_result_littleendian = 0x9B08
203 |
204 |
205 | class ChecksumXor8(ChecksumXorBase):
206 | """ 8-bit XOR checksum.
207 |
208 | Calculates 8-bit checksum by XOR-ing the input bytes.
209 | """
210 | _width = 8
211 | _mask = 0xFF
212 | _check_result = 0x93
213 | _check_result_littleendian = _check_result
214 |
215 |
216 | class Checksum(ChecksumBase):
217 | """ General additive checksum.
218 |
219 | Args:
220 | width (int): bit width of checksum. Must be positive and a multiple of 8.
221 | initvalue (int): Initial value. If None then the default value for the class is used.
222 | byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes.
223 | """
224 | _check_result = None
225 | _check_result_littleendian = None
226 |
227 | def __init__(self, width, initvalue=0, byteorder='big'):
228 | super(Checksum, self).__init__(initvalue, byteorder)
229 | width = int(width)
230 | if width <= 0 or width % 8 != 0:
231 | raise ValueError("width must be postive and a multiple of 8")
232 | self._width = width
233 | self._mask = (1 << width) - 1
234 |
235 |
236 | class ChecksumXor(ChecksumXorBase):
237 | """ General XOR checksum.
238 |
239 | Args:
240 | width (int): bit width of checksum. Must be positive and a multiple of 8.
241 | initvalue (int): Initial value. If None then the default value for the class is used.
242 | byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes.
243 | """
244 | _check_result = None
245 | _check_result_littleendian = None
246 |
247 | def __init__(self, width, initvalue=0, byteorder='big'):
248 | super(ChecksumXor, self).__init__(initvalue, byteorder)
249 | width = int(width)
250 | if width <= 0 or width % 8 != 0:
251 | raise ValueError("width must be postive and a multiple of 8")
252 | self._width = width
253 | self._mask = (1 << width) - 1
254 |
255 |
256 | ALLCHECKSUMCLASSES = (
257 | Checksum8, Checksum16, Checksum32,
258 | ChecksumXor8, ChecksumXor16, ChecksumXor32,
259 | )
260 |
--------------------------------------------------------------------------------
/tests/test_crc.py:
--------------------------------------------------------------------------------
1 | """ Unit tests for checksum module.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | import random
26 | import sys
27 |
28 | import crccheck
29 | from crccheck.base import CrccheckError
30 | from crccheck.crc import ALLCRCCLASSES, ALLCRCCLASSES_ALIASES, \
31 | Crc32, Crc, crccls, find, identify, \
32 | Crc8Base, Crc16Base, Crc32Base
33 | from tests import TestCase
34 |
35 | TESTCRCCLASSES = list(ALLCRCCLASSES) + [Crc8Base, Crc16Base, Crc32Base]
36 |
37 |
38 | class TestCrc(TestCase):
39 |
40 | def test_allcrc(self):
41 | """Test if expected 'check' result is calulated with standard test vector."""
42 | for crcclass in TESTCRCCLASSES:
43 | with self.subTest(crcclass=crcclass):
44 | crcclass.selftest()
45 |
46 | def test_allcrcfail(self):
47 | """Test if 'check' result is not reached with different input."""
48 | for crcclass in TESTCRCCLASSES:
49 | with self.subTest(crcclass=crcclass), self.assertRaises(CrccheckError):
50 | crcclass.selftest(bytearray(b"wrongtestinput"), crcclass._check_result)
51 |
52 | def test_generator(self):
53 | Crc32.calc((n for n in range(0, 255)))
54 |
55 | def test_list1(self):
56 | Crc32.calc([n for n in range(0, 255)])
57 |
58 | def test_list2(self):
59 | Crc32.calc([n for n in range(0, 255)], 123)
60 |
61 | def test_bytearray(self):
62 | Crc32.calc(bytearray.fromhex("12345678909876543210"))
63 |
64 | def test_bytes(self):
65 | if sys.version_info < (3, 3, 0): # pragma: no cover
66 | raise self.skipTest("")
67 | Crc32.calc(bytes.fromhex("12345678909876543210"))
68 |
69 | def test_string1(self):
70 | if sys.version_info < (3, 3, 0): # pragma: no cover
71 | raise self.skipTest("")
72 | Crc32.calc(b"Teststring")
73 |
74 | def test_string2(self):
75 | if sys.version_info < (3, 3, 0): # pragma: no cover
76 | raise self.skipTest("")
77 | Crc32.calc("Teststring".encode(), )
78 |
79 | def test_general_crc(self):
80 | crc = Crc(32, 0x4C11DB7, 0xFFFFFFFF, True, True, 0x00000000, 0x340BC6D9)
81 | crc.selftest()
82 |
83 | def test_general_crc_fail(self):
84 | with self.assertRaises(CrccheckError):
85 | crc = Crc(32, 0x4C11DB7, 0xFFFFFFFF, True, True, 0x00000000, ~0x340BC6D9)
86 | crc.selftest()
87 |
88 | def test_general_crccls(self):
89 | crc = crccls(32, 0x4C11DB7, 0xFFFFFFFF, True, True, 0x00000000, 0x340BC6D9)
90 | crc.selftest()
91 |
92 | def test_general_crccls_fail(self):
93 | with self.assertRaises(CrccheckError):
94 | crc = crccls(32, 0x4C11DB7, 0xFFFFFFFF, True, True, 0x00000000, ~0x340BC6D9)
95 | crc.selftest()
96 |
97 | def test_backwards_compatible(self):
98 | """Crc8Base was called Crc8, etc. Must still be equal CRCs"""
99 | self.assertEqual(crccheck.crc.Crc8(), crccheck.crc.Crc8Base())
100 | self.assertEqual(crccheck.crc.Crc16(), crccheck.crc.Crc16Base())
101 | self.assertEqual(crccheck.crc.Crc32(), crccheck.crc.Crc32Base())
102 |
103 | def test_find32(self):
104 | for cls in find(width=32):
105 | self.assertEqual(cls._width, 32)
106 |
107 | def test_find_unknown(self):
108 | self.assertEqual(len(find(width=12345)), 0)
109 |
110 | def test_find_all(self):
111 | self.assertEqual(find(), list(ALLCRCCLASSES))
112 |
113 | def test_find_some(self):
114 | self.assertListEqual(find(ALLCRCCLASSES[1:3]), list(ALLCRCCLASSES[1:3]))
115 |
116 | def test_find_width(self):
117 | self.assertListEqual(find(width=32), list(cls for cls in ALLCRCCLASSES if cls._width == 32))
118 |
119 | def test_find_poly(self):
120 | self.assertListEqual(find(poly=0x04C11DB7), list(cls for cls in ALLCRCCLASSES if cls._poly == 0x04C11DB7))
121 |
122 | def test_find_initvalue(self):
123 | self.assertListEqual(find(initvalue=0), list(cls for cls in ALLCRCCLASSES if cls._initvalue == 0))
124 |
125 | def test_find_reflect_input(self):
126 | self.assertListEqual(find(reflect_input=True), list(cls for cls in ALLCRCCLASSES if cls._reflect_input))
127 |
128 | def test_find_reflect_output(self):
129 | self.assertListEqual(find(reflect_output=False), list(cls for cls in ALLCRCCLASSES if not cls._reflect_output))
130 |
131 | def test_find_xor_output(self):
132 | self.assertListEqual(find(xor_output=0), list(cls for cls in ALLCRCCLASSES if cls._xor_output == 0))
133 |
134 | def test_find_check_result(self):
135 | self.assertListEqual(find(check_result=6), list(cls for cls in ALLCRCCLASSES if cls._check_result == 6))
136 |
137 | def test_find_residue(self):
138 | self.assertListEqual(find(residue=0), list(cls for cls in ALLCRCCLASSES if cls._residue == 0))
139 |
140 | def test_find_mixed(self):
141 | self.assertListEqual(
142 | find(ALLCRCCLASSES[0:20], width=8, residue=0, reflect_input=False, reflect_output=False),
143 | list(cls for cls in ALLCRCCLASSES[0:20]
144 | if cls._width == 8 and cls._residue == 0 and not cls._reflect_input and not cls._reflect_output))
145 |
146 | def test_identify_1(self):
147 | data = bytes(random.randrange(256) for _ in range(10))
148 | cls = crccheck.crc.Crc64GoIso
149 | self.assertEqual(identify(data, cls.calc(data))(), cls())
150 |
151 | def test_identify_2(self):
152 | data = bytes(random.randrange(256) for _ in range(10))
153 | classes = [crccheck.crc.Crc64GoIso, crccheck.crc.Crc8, crccheck.crc.Crc32IsoHdlc]
154 | cls = crccheck.crc.Crc32IsoHdlc
155 | self.assertEqual(identify(data, cls.calc(data), classes=classes)(), cls())
156 |
157 | def test_identify_width(self):
158 | data = bytes(random.randrange(256) for _ in range(10))
159 | allcrc32 = [c for c in ALLCRCCLASSES if c._width == 32]
160 | cls = random.choice(allcrc32)
161 | self.assertEqual(identify(data, cls.calc(data), 32)(), cls())
162 | self.assertEqual(identify(data, cls.calc(data), 32, allcrc32)(), cls())
163 |
164 | def test_identify_width_list(self):
165 | data = bytes(random.randrange(256) for _ in range(10))
166 | allcrc32 = [c for c in ALLCRCCLASSES if c._width == 32]
167 | cls = random.choice(allcrc32)
168 | result = identify(data, cls.calc(data), 32, one=False)
169 | self.assertEqual(len(result) >= 1 and result[0](), cls())
170 | result = identify(data, cls.calc(data), 32, allcrc32, one=False)
171 | self.assertEqual(len(result) >= 1 and result[0](), cls())
172 |
173 | def test_identify_notexisting(self):
174 | self.assertIsNone(identify(b'Test', 0))
175 | self.assertIsNone(identify(b'Test', 0, 234))
176 | self.assertIsNone(identify(b'Test', 0, classes=[]))
177 | self.assertIsNone(identify(b'Test', 0, 235, classes=[]))
178 | self.assertListEqual(identify(b'Test', 0, one=False), [])
179 | self.assertListEqual(identify(b'Test', 0, 234, one=False), [])
180 | self.assertListEqual(identify(b'Test', 0, classes=[], one=False), [])
181 | self.assertListEqual(identify(b'Test', 0, 235, classes=[], one=False), [])
182 |
183 | def test_repr(self):
184 | """Test if __repr__ does not cause errors"""
185 | c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False,
186 | xor_output=0x00, check_result=None, residue=None)
187 | # noinspection PyUnusedLocal
188 | r = repr(c)
189 | c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False,
190 | xor_output=0x00, check_result=None, residue=0x00)
191 | # noinspection PyUnusedLocal
192 | r = repr(c)
193 | c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False,
194 | xor_output=0x00, check_result=0x00, residue=None)
195 | # noinspection PyUnusedLocal
196 | r = repr(c)
197 | c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False,
198 | xor_output=0x00, check_result=0x00, residue=0x00)
199 | # noinspection PyUnusedLocal
200 | r = repr(c)
201 |
202 | def test_selftest_data(self):
203 | c = Crc(21, 0xDEAD)
204 | c.selftest(b'Test', 0x40be8)
205 |
206 | def test_crc_calc(self):
207 | self.assertEqual(Crc(21, 0xDEAD).calc(b'Test'), 265192)
208 |
209 | def test_crc_calchex(self):
210 | self.assertEqual(Crc(21, 0xDEAD).calchex(b'Test'), '040be8')
211 |
212 | def test_crc_calcbytes_big(self):
213 | self.assertEqual(Crc(21, 0xDEAD).calcbytes(b'Test', byteorder='big'), b'\x04\x0b\xe8')
214 |
215 | def test_crc_calcbytes_little(self):
216 | self.assertEqual(Crc(21, 0xDEAD).calcbytes(b'Test', byteorder='little'), b'\xe8\x0b\x04')
217 |
218 | def test_aliases(self):
219 | self.assertTrue(set(ALLCRCCLASSES).issubset(ALLCRCCLASSES_ALIASES))
220 |
221 | def test_getter(self):
222 | """Test if all getter return the underlying value correctly."""
223 | for cls in ALLCRCCLASSES:
224 | for attr in ("poly", "reflect_input", "reflect_output", "xor_output", "residue"):
225 | for clsorinst in (cls, cls()):
226 | with self.subTest(clsorinst=clsorinst, attr=attr):
227 | # x.foo() should return x._foo
228 | self.assertEqual(getattr(clsorinst, attr)(), getattr(clsorinst, "_" + attr))
229 |
--------------------------------------------------------------------------------
/crccheck/base.py:
--------------------------------------------------------------------------------
1 | """ Base class for CRC and checksum classes.
2 |
3 | License::
4 |
5 | MIT License
6 |
7 | Copyright (c) 2015-2022 by Martin Scharrer
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10 | and associated documentation files (the "Software"), to deal in the Software without
11 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
13 | Software is furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all copies or
16 | substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | """
25 | import math
26 |
27 | REFLECT_BIT_ORDER_TABLE = bytes((
28 | 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
29 | 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
30 | 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
31 | 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
32 | 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
33 | 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
34 | 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
35 | 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
36 | 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
37 | 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
38 | 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
39 | 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
40 | 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
41 | 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
42 | 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
43 | 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
44 | 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
45 | 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
46 | 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
47 | 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
48 | 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
49 | 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
50 | 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
51 | 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
52 | 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
53 | 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
54 | 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
55 | 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
56 | 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
57 | 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
58 | 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
59 | 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF,
60 | ))
61 |
62 |
63 | def reflectbitorder(width, value):
64 | """ Reflects the bit order of the given value according to the given bit width.
65 |
66 | Args:
67 | width (int): bitwidth
68 | value (int): value to reflect
69 | """
70 | binstr = ("0" * width + bin(value)[2:])[-width:]
71 | return int(binstr[::-1], 2)
72 |
73 |
74 | class CrccheckError(Exception):
75 | """General checksum error exception"""
76 | pass
77 |
78 |
79 | class CrccheckBase(object):
80 | """ Abstract base class for checksumming classes.
81 |
82 | Args:
83 | initvalue (int): Initial value. If None then the default value for the class is used.
84 | """
85 | _initvalue = 0x00
86 | _check_result = None
87 | _check_data = None
88 | _width = 0
89 |
90 | def __init__(self, initvalue=None, **kwargs):
91 | if initvalue is None:
92 | self._value = self._initvalue
93 | else:
94 | self._value = initvalue
95 |
96 | @classmethod
97 | def initvalue(cls):
98 | """Getter for initvalue."""
99 | return cls._initvalue
100 |
101 | @classmethod
102 | def check_result(cls):
103 | """Getter for check_result."""
104 | return cls._check_result
105 |
106 | @classmethod
107 | def check_data(cls):
108 | """Getter for check_data."""
109 | return cls._check_data
110 |
111 | @classmethod
112 | def width(cls):
113 | return cls._width
114 |
115 | @classmethod
116 | def bytewidth(cls):
117 | return (cls._width + 7) // 8
118 |
119 | def reset(self, value=None):
120 | """ Reset instance.
121 |
122 | Resets the instance state to the initial value.
123 | This is not required for a just created instance.
124 |
125 | Args:
126 | value (int): Set internal value. If None then the default initial value for the class is used.
127 |
128 | Returns:
129 | self
130 | """
131 | if value is None:
132 | self._value = self._initvalue
133 | else:
134 | self._value = value
135 | return self
136 |
137 | def process(self, data):
138 | """ Process given data.
139 |
140 | Args:
141 | data (bytes, bytearray or list of ints [0-255]): input data to process.
142 |
143 | Returns:
144 | self
145 | """
146 | raise NotImplementedError
147 |
148 | def final(self):
149 | """Return final check value.
150 | The internal state is not modified by this so further data can be processed afterwards.
151 |
152 | Return:
153 | int: final value
154 | """
155 | return self._value
156 |
157 | def finalhex(self, byteorder='big'):
158 | """Return final checksum value as hexadecimal string (without leading "0x").
159 | The hex value is zero padded to bitwidth/8.
160 | The internal state is not modified by this so further data can be processed afterwards.
161 |
162 | Return:
163 | str: final value as hex string without leading '0x'.
164 | """
165 | asbytes = self.finalbytes(byteorder)
166 | try:
167 | # bytearray.hex() is new in Python 3.5
168 | return asbytes.hex()
169 | except AttributeError: # pragma: no cover
170 | return "".join(["{:02x}".format(b) for b in asbytes])
171 |
172 | def finalbytes(self, byteorder='big'):
173 | """Return final checksum value as bytes.
174 | The internal state is not modified by this so further data can be processed afterwards.
175 |
176 | Return:
177 | bytes: final value as bytes
178 | """
179 | bytelength = int(math.ceil(self._width / 8.0))
180 | asint = self.final()
181 | try:
182 | # int.to_bytes() is new in Python 3.2
183 | return asint.to_bytes(bytelength, byteorder)
184 | except AttributeError: # pragma: no cover
185 | asbytes = bytearray(bytelength)
186 | for i in range(0, bytelength):
187 | asbytes[i] = asint & 0xFF
188 | asint >>= 8
189 | if byteorder == 'big':
190 | asbytes.reverse()
191 | return asbytes
192 |
193 | def value(self):
194 | """Returns current intermediate value.
195 | Note that in general final() must be used to get the final value.
196 |
197 | Return:
198 | int: current value
199 | """
200 | return self._value
201 |
202 | @classmethod
203 | def calc(cls, data, initvalue=None, **kwargs):
204 | """ Fully calculate CRC/checksum over given data.
205 |
206 | Args:
207 | data (bytes, bytearray or list of ints [0-255]): input data to process.
208 | initvalue (int): Initial value. If None then the default value for the class is used.
209 |
210 | Return:
211 | int: final value
212 | """
213 | inst = cls(initvalue, **kwargs)
214 | inst.process(data)
215 | return inst.final()
216 |
217 | @classmethod
218 | def calchex(cls, data, initvalue=None, byteorder='big', **kwargs):
219 | """Fully calculate checksum over given data. Return result as hex string.
220 |
221 | Args:
222 | data (bytes, bytearray or list of ints [0-255]): input data to process.
223 | initvalue (int): Initial value. If None then the default value for the class is used.
224 | byteorder ('big' or 'little'): order (endianness) of returned bytes.
225 |
226 | Return:
227 | str: final value as hex string without leading '0x'.
228 | """
229 | inst = cls(initvalue, **kwargs)
230 | inst.process(data)
231 | return inst.finalhex(byteorder)
232 |
233 | @classmethod
234 | def calcbytes(cls, data, initvalue=None, byteorder='big', **kwargs):
235 | """Fully calculate checksum over given data. Return result as bytearray.
236 |
237 | Args:
238 | data (bytes, bytearray or list of ints [0-255]): input data to process.
239 | initvalue (int): Initial value. If None then the default value for the class is used.
240 | byteorder ('big' or 'little'): order (endianness) of returned bytes.
241 |
242 | Return:
243 | bytes: final value as bytes
244 | """
245 | inst = cls(initvalue, **kwargs)
246 | inst.process(data)
247 | return inst.finalbytes(byteorder)
248 |
249 | @classmethod
250 | def selftest(cls, data=None, expectedresult=None, **kwargs):
251 | """ Selftest method for automated tests.
252 |
253 | Args:
254 | data (bytes, bytearray or list of int [0-255]): data to process
255 | expectedresult (int): expected result
256 |
257 | Raises:
258 | CrccheckError: if result is not as expected
259 | """
260 | if data is None:
261 | data = cls._check_data
262 | expectedresult = cls._check_result
263 | result = cls.calc(data, **kwargs)
264 | if result != expectedresult:
265 | raise CrccheckError("{:s}: expected {:s}, got {:s}".format(cls.__name__, hex(expectedresult), hex(result)))
266 |
267 | def copy(self):
268 | """Creates a copy of the Crc/Checksum instance. This can be used to efficiently compute the CRC/checksum of data
269 | sharing common initial part."""
270 | import copy
271 | return copy.deepcopy(self)
272 |
--------------------------------------------------------------------------------
/docs/source/conf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # crccheck documentation build configuration file, created by
4 | # sphinx-quickstart on Thu Apr 09 22:32:46 2015.
5 | #
6 | # This file is execfile()d with the current directory set to its
7 | # containing dir.
8 | #
9 | # Note that not all possible configuration values are present in this
10 | # autogenerated file.
11 | #
12 | # All configuration values have a default; values that are commented out
13 | # serve to show the default.
14 |
15 | import os
16 | import sys
17 |
18 | # If extensions (or modules to document with autodoc) are in another directory,
19 | # add these directories to sys.path here. If the directory is relative to the
20 | # documentation root, use os.path.abspath to make it absolute, like shown here.
21 | sys.path.insert(0, os.path.abspath('../..'))
22 |
23 | # -- General configuration ------------------------------------------------
24 |
25 | # If your documentation needs a minimal Sphinx version, state it here.
26 | #needs_sphinx = '1.0'
27 |
28 | # Add any Sphinx extension module names here, as strings. They can be
29 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
30 | # ones.
31 | extensions = [
32 | 'sphinx.ext.autodoc',
33 | 'sphinx.ext.intersphinx',
34 | 'sphinx.ext.todo',
35 | 'sphinx.ext.coverage',
36 | 'sphinx.ext.ifconfig',
37 | 'sphinx.ext.viewcode',
38 | 'sphinx.ext.napoleon',
39 | ]
40 |
41 | # Add any paths that contain templates here, relative to this directory.
42 | templates_path = ['_templates']
43 |
44 | # The suffix(es) of source filenames.
45 | # You can specify multiple suffix as a list of string:
46 | # source_suffix = ['.rst', '.md']
47 | source_suffix = '.rst'
48 |
49 | # The encoding of source files.
50 | #source_encoding = 'utf-8-sig'
51 |
52 | # The master toctree document.
53 | master_doc = 'index'
54 |
55 | # General information about the project.
56 | project = u'crccheck'
57 | copyright = u'2015-2020, Martin Scharrer'
58 | author = u'Martin Scharrer'
59 |
60 | # The version info for the project you're documenting, acts as replacement for
61 | # |version| and |release|, also used in various other places throughout the
62 | # built documents.
63 | #
64 | # The short X.Y version.
65 | version = '1.3'
66 | # The full version, including alpha/beta/rc tags.
67 | release = '1.3.0'
68 |
69 | # The language for content autogenerated by Sphinx. Refer to documentation
70 | # for a list of supported languages.
71 | #
72 | # This is also used if you do content translation via gettext catalogs.
73 | # Usually you set "language" from the command line for these cases.
74 | language = 'en'
75 |
76 | # There are two options for replacing |today|: either, you set today to some
77 | # non-false value, then it is used:
78 | #today = ''
79 | # Else, today_fmt is used as the format for a strftime call.
80 | #today_fmt = '%B %d, %Y'
81 |
82 | # List of patterns, relative to source directory, that match files and
83 | # directories to ignore when looking for source files.
84 | exclude_patterns = []
85 |
86 | # The reST default role (used for this markup: `text`) to use for all
87 | # documents.
88 | #default_role = None
89 |
90 | # If true, '()' will be appended to :func: etc. cross-reference text.
91 | #add_function_parentheses = True
92 |
93 | # If true, the current module name will be prepended to all description
94 | # unit titles (such as .. function::).
95 | #add_module_names = True
96 |
97 | # If true, sectionauthor and moduleauthor directives will be shown in the
98 | # output. They are ignored by default.
99 | #show_authors = False
100 |
101 | # The name of the Pygments (syntax highlighting) style to use.
102 | pygments_style = 'sphinx'
103 |
104 | # A list of ignored prefixes for module index sorting.
105 | #modindex_common_prefix = []
106 |
107 | # If true, keep warnings as "system message" paragraphs in the built documents.
108 | #keep_warnings = False
109 |
110 | # If true, `todo` and `todoList` produce output, else they produce nothing.
111 | todo_include_todos = True
112 |
113 |
114 | # -- Options for HTML output ----------------------------------------------
115 |
116 | # The theme to use for HTML and HTML Help pages. See the documentation for
117 | # a list of builtin themes.
118 | html_theme = 'classic'
119 |
120 | # Theme options are theme-specific and customize the look and feel of a theme
121 | # further. For a list of options available for each theme, see the
122 | # documentation.
123 | #html_theme_options = {}
124 |
125 | # Add any paths that contain custom themes here, relative to this directory.
126 | #html_theme_path = []
127 |
128 | # The name for this set of Sphinx documents. If None, it defaults to
129 | # " v documentation".
130 | #html_title = None
131 |
132 | # A shorter title for the navigation bar. Default is the same as html_title.
133 | #html_short_title = None
134 |
135 | # The name of an image file (relative to this directory) to place at the top
136 | # of the sidebar.
137 | #html_logo = None
138 |
139 | # The name of an image file (within the static path) to use as favicon of the
140 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
141 | # pixels large.
142 | #html_favicon = None
143 |
144 | # Add any paths that contain custom static files (such as style sheets) here,
145 | # relative to this directory. They are copied after the builtin static files,
146 | # so a file named "default.css" will overwrite the builtin "default.css".
147 | html_static_path = ['_static']
148 |
149 | # Add any extra paths that contain custom files (such as robots.txt or
150 | # .htaccess) here, relative to this directory. These files are copied
151 | # directly to the root of the documentation.
152 | #html_extra_path = []
153 |
154 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
155 | # using the given strftime format.
156 | #html_last_updated_fmt = '%b %d, %Y'
157 |
158 | # If true, SmartyPants will be used to convert quotes and dashes to
159 | # typographically correct entities.
160 | #html_use_smartypants = True
161 |
162 | # Custom sidebar templates, maps document names to template names.
163 | html_sidebars = {
164 | '**': ['globaltoc.html', 'searchbox.html'],
165 | 'using/windows': ['windowssidebar.html', 'searchbox.html'],
166 | }
167 |
168 | # Additional templates that should be rendered to pages, maps page names to
169 | # template names.
170 | #html_additional_pages = {}
171 |
172 | # If false, no module index is generated.
173 | #html_domain_indices = True
174 |
175 | # If false, no index is generated.
176 | #html_use_index = True
177 |
178 | # If true, the index is split into individual pages for each letter.
179 | #html_split_index = False
180 |
181 | # If true, links to the reST sources are added to the pages.
182 | #html_show_sourcelink = True
183 |
184 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
185 | #html_show_sphinx = True
186 |
187 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
188 | #html_show_copyright = True
189 |
190 | # If true, an OpenSearch description file will be output, and all pages will
191 | # contain a tag referring to it. The value of this option must be the
192 | # base URL from which the finished HTML is served.
193 | #html_use_opensearch = ''
194 |
195 | # This is the file name suffix for HTML files (e.g. ".xhtml").
196 | #html_file_suffix = None
197 |
198 | # Language to be used for generating the HTML full-text search index.
199 | # Sphinx supports the following languages:
200 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
201 | # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
202 | #html_search_language = 'en'
203 |
204 | # A dictionary with options for the search language support, empty by default.
205 | # Now only 'ja' uses this config value
206 | #html_search_options = {'type': 'default'}
207 |
208 | # The name of a javascript file (relative to the configuration directory) that
209 | # implements a search results scorer. If empty, the default will be used.
210 | #html_search_scorer = 'scorer.js'
211 |
212 | # Output file base name for HTML help builder.
213 | htmlhelp_basename = 'crccheckdoc'
214 |
215 | # -- Options for LaTeX output ---------------------------------------------
216 |
217 | latex_elements = {
218 | # The paper size ('letterpaper' or 'a4paper').
219 | #'papersize': 'letterpaper',
220 |
221 | # The font size ('10pt', '11pt' or '12pt').
222 | #'pointsize': '10pt',
223 |
224 | # Additional stuff for the LaTeX preamble.
225 | #'preamble': '',
226 |
227 | # Latex figure (float) alignment
228 | #'figure_align': 'htbp',
229 | }
230 |
231 | # Grouping the document tree into LaTeX files. List of tuples
232 | # (source start file, target name, title,
233 | # author, documentclass [howto, manual, or own class]).
234 | latex_documents = [
235 | (master_doc, 'crccheck.tex', u'crccheck Documentation',
236 | u'Martin Scharrer', 'manual'),
237 | ]
238 |
239 | # The name of an image file (relative to this directory) to place at the top of
240 | # the title page.
241 | #latex_logo = None
242 |
243 | # For "manual" documents, if this is true, then toplevel headings are parts,
244 | # not chapters.
245 | #latex_use_parts = False
246 |
247 | # If true, show page references after internal links.
248 | #latex_show_pagerefs = False
249 |
250 | # If true, show URL addresses after external links.
251 | #latex_show_urls = False
252 |
253 | # Documents to append as an appendix to all manuals.
254 | #latex_appendices = []
255 |
256 | # If false, no module index is generated.
257 | #latex_domain_indices = True
258 |
259 |
260 | # -- Options for manual page output ---------------------------------------
261 |
262 | # One entry per manual page. List of tuples
263 | # (source start file, name, description, authors, manual section).
264 | man_pages = [
265 | (master_doc, 'crccheck', u'crccheck Documentation',
266 | [author], 1)
267 | ]
268 |
269 | # If true, show URL addresses after external links.
270 | #man_show_urls = False
271 |
272 |
273 | # -- Options for Texinfo output -------------------------------------------
274 |
275 | # Grouping the document tree into Texinfo files. List of tuples
276 | # (source start file, target name, title, author,
277 | # dir menu entry, description, category)
278 | texinfo_documents = [
279 | (master_doc, 'crccheck', u'crccheck Documentation',
280 | author, 'crccheck', 'One line description of project.',
281 | 'Miscellaneous'),
282 | ]
283 |
284 | # Documents to append as an appendix to all manuals.
285 | #texinfo_appendices = []
286 |
287 | # If false, no module index is generated.
288 | #texinfo_domain_indices = True
289 |
290 | # How to display URL addresses: 'footnote', 'no', or 'inline'.
291 | #texinfo_show_urls = 'footnote'
292 |
293 | # If true, do not generate a @detailmenu in the "Top" node's menu.
294 | #texinfo_no_detailmenu = False
295 |
296 |
297 | # Example configuration for intersphinx: refer to the Python standard library.
298 | intersphinx_mapping = {'https://docs.python.org/': None}
299 |
300 | autodoc_member_order='bysource'
301 |
302 | autodoc_default_flags = ['members', 'undoc-members', 'show-inheritance']
303 | # [ 'members', 'undoc-members', 'private-members', 'special-members', 'inherited-members', 'show-inheritance']
304 |
305 | # Napoleon settings
306 | napoleon_google_docstring = True
307 | napoleon_numpy_docstring = True
308 | napoleon_include_private_with_doc = False
309 | napoleon_include_special_with_doc = False
310 | napoleon_use_admonition_for_examples = False
311 | napoleon_use_admonition_for_notes = False
312 | napoleon_use_admonition_for_references = False
313 | napoleon_use_ivar = False
314 | napoleon_use_param = True
315 | napoleon_use_rtype = True
316 |
--------------------------------------------------------------------------------
/docs/source/crctable.rst:
--------------------------------------------------------------------------------
1 | Supported CRCs
2 | ==============
3 |
4 |
5 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
6 | | CRC Name | Class | Bit width | Poly | Initvalue | Reflect input | Reflect output | XOR output | Check | Residue |
7 | +==========================+====================+===========+==========================+======================+===============+================+======================+==========================+======================+
8 | | CRC-3/GSM | Crc3Gsm | 3 | 0x3 | 0x0 | False | False | 0x7 | 0x4 | 0x2 |
9 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
10 | | CRC-3/ROHC | Crc3Rohc | 3 | 0x3 | 0x7 | True | True | 0x0 | 0x6 | 0x0 |
11 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
12 | | CRC-4/G-704 | Crc4G704 | 4 | 0x3 | 0x0 | True | True | 0x0 | 0x7 | 0x0 |
13 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
14 | | CRC-4/INTERLAKEN | Crc4Interlaken | 4 | 0x3 | 0xF | False | False | 0xF | 0xB | 0x2 |
15 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
16 | | CRC-5/EPC-C1G2 | Crc5EpcC1G2 | 5 | 0x9 | 0x9 | False | False | 0x0 | 0x0 | 0x0 |
17 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
18 | | CRC-5/G-704 | Crc5G704 | 5 | 0x15 | 0x0 | True | True | 0x0 | 0x7 | 0x0 |
19 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
20 | | CRC-5/USB | Crc5Usb | 5 | 0x5 | 0x1F | True | True | 0x1F | 0x19 | 0x6 |
21 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
22 | | CRC-6/CDMA2000-A | Crc6Cdma2000A | 6 | 0x27 | 0x3F | False | False | 0x0 | 0xD | 0x0 |
23 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
24 | | CRC-6/CDMA2000-B | Crc6Cdma2000B | 6 | 0x7 | 0x3F | False | False | 0x0 | 0x3B | 0x0 |
25 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
26 | | CRC-6/DARC | Crc6Darc | 6 | 0x19 | 0x0 | True | True | 0x0 | 0x26 | 0x0 |
27 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
28 | | CRC-6/G-704 | Crc6G704 | 6 | 0x3 | 0x0 | True | True | 0x0 | 0x6 | 0x0 |
29 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
30 | | CRC-6/GSM | Crc6Gsm | 6 | 0x2F | 0x0 | False | False | 0x3F | 0x13 | 0x3A |
31 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
32 | | CRC-7/MMC | Crc7Mmc | 7 | 0x9 | 0x0 | False | False | 0x0 | 0x75 | 0x0 |
33 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
34 | | CRC-7/ROHC | Crc7Rohc | 7 | 0x4F | 0x7F | True | True | 0x0 | 0x53 | 0x0 |
35 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
36 | | CRC-7/UMTS | Crc7Umts | 7 | 0x45 | 0x0 | False | False | 0x0 | 0x61 | 0x0 |
37 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
38 | | CRC-8/AUTOSAR | Crc8Autosar | 8 | 0x2F | 0xFF | False | False | 0xFF | 0xDF | 0x42 |
39 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
40 | | CRC-8/BLUETOOTH | Crc8Bluetooth | 8 | 0xA7 | 0x0 | True | True | 0x0 | 0x26 | 0x0 |
41 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
42 | | CRC-8/CDMA2000 | Crc8Cdma2000 | 8 | 0x9B | 0xFF | False | False | 0x0 | 0xDA | 0x0 |
43 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
44 | | CRC-8/DARC | Crc8Darc | 8 | 0x39 | 0x0 | True | True | 0x0 | 0x15 | 0x0 |
45 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
46 | | CRC-8/DVB-S2 | Crc8DvbS2 | 8 | 0xD5 | 0x0 | False | False | 0x0 | 0xBC | 0x0 |
47 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
48 | | CRC-8/GSM-A | Crc8GsmA | 8 | 0x1D | 0x0 | False | False | 0x0 | 0x37 | 0x0 |
49 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
50 | | CRC-8/GSM-B | Crc8GsmB | 8 | 0x49 | 0x0 | False | False | 0xFF | 0x94 | 0x53 |
51 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
52 | | CRC-8/HITAG | Crc8Hitag | 8 | 0x1D | 0xFF | False | False | 0x0 | 0xB4 | 0x0 |
53 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
54 | | CRC-8/I-432-1 | Crc8I4321 | 8 | 0x7 | 0x0 | False | False | 0x55 | 0xA1 | 0xAC |
55 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
56 | | CRC-8/I-CODE | Crc8ICode | 8 | 0x1D | 0xFD | False | False | 0x0 | 0x7E | 0x0 |
57 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
58 | | CRC-8/LTE | Crc8Lte | 8 | 0x9B | 0x0 | False | False | 0x0 | 0xEA | 0x0 |
59 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
60 | | CRC-8/MAXIM-DOW | Crc8MaximDow | 8 | 0x31 | 0x0 | True | True | 0x0 | 0xA1 | 0x0 |
61 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
62 | | CRC-8/MIFARE-MAD | Crc8MifareMad | 8 | 0x1D | 0xC7 | False | False | 0x0 | 0x99 | 0x0 |
63 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
64 | | CRC-8/NRSC-5 | Crc8Nrsc5 | 8 | 0x31 | 0xFF | False | False | 0x0 | 0xF7 | 0x0 |
65 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
66 | | CRC-8/OPENSAFETY | Crc8Opensafety | 8 | 0x2F | 0x0 | False | False | 0x0 | 0x3E | 0x0 |
67 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
68 | | CRC-8/ROHC | Crc8Rohc | 8 | 0x7 | 0xFF | True | True | 0x0 | 0xD0 | 0x0 |
69 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
70 | | CRC-8/SAE-J1850 | Crc8SaeJ1850 | 8 | 0x1D | 0xFF | False | False | 0xFF | 0x4B | 0xC4 |
71 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
72 | | CRC-8/SMBUS | Crc8Smbus | 8 | 0x7 | 0x0 | False | False | 0x0 | 0xF4 | 0x0 |
73 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
74 | | CRC-8/TECH-3250 | Crc8Tech3250 | 8 | 0x1D | 0xFF | True | True | 0x0 | 0x97 | 0x0 |
75 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
76 | | CRC-8/WCDMA | Crc8Wcdma | 8 | 0x9B | 0x0 | True | True | 0x0 | 0x25 | 0x0 |
77 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
78 | | CRC-10/ATM | Crc10Atm | 10 | 0x233 | 0x0 | False | False | 0x0 | 0x199 | 0x0 |
79 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
80 | | CRC-10/CDMA2000 | Crc10Cdma2000 | 10 | 0x3D9 | 0x3FF | False | False | 0x0 | 0x233 | 0x0 |
81 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
82 | | CRC-10/GSM | Crc10Gsm | 10 | 0x175 | 0x0 | False | False | 0x3FF | 0x12A | 0xC6 |
83 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
84 | | CRC-11/FLEXRAY | Crc11Flexray | 11 | 0x385 | 0x1A | False | False | 0x0 | 0x5A3 | 0x0 |
85 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
86 | | CRC-11/UMTS | Crc11Umts | 11 | 0x307 | 0x0 | False | False | 0x0 | 0x61 | 0x0 |
87 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
88 | | CRC-12/CDMA2000 | Crc12Cdma2000 | 12 | 0xF13 | 0xFFF | False | False | 0x0 | 0xD4D | 0x0 |
89 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
90 | | CRC-12/DECT | Crc12Dect | 12 | 0x80F | 0x0 | False | False | 0x0 | 0xF5B | 0x0 |
91 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
92 | | CRC-12/GSM | Crc12Gsm | 12 | 0xD31 | 0x0 | False | False | 0xFFF | 0xB34 | 0x178 |
93 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
94 | | CRC-12/UMTS | Crc12Umts | 12 | 0x80F | 0x0 | False | True | 0x0 | 0xDAF | 0x0 |
95 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
96 | | CRC-13/BBC | Crc13Bbc | 13 | 0x1CF5 | 0x0 | False | False | 0x0 | 0x4FA | 0x0 |
97 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
98 | | CRC-14/DARC | Crc14Darc | 14 | 0x805 | 0x0 | True | True | 0x0 | 0x82D | 0x0 |
99 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
100 | | CRC-14/GSM | Crc14Gsm | 14 | 0x202D | 0x0 | False | False | 0x3FFF | 0x30AE | 0x31E |
101 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
102 | | CRC-15/CAN | Crc15Can | 15 | 0x4599 | 0x0 | False | False | 0x0 | 0x59E | 0x0 |
103 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
104 | | CRC-15/MPT1327 | Crc15Mpt1327 | 15 | 0x6815 | 0x0 | False | False | 0x1 | 0x2566 | 0x6815 |
105 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
106 | | CRC-16/ARC | Crc16Arc | 16 | 0x8005 | 0x0 | True | True | 0x0 | 0xBB3D | 0x0 |
107 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
108 | | CRC-16/CDMA2000 | Crc16Cdma2000 | 16 | 0xC867 | 0xFFFF | False | False | 0x0 | 0x4C06 | 0x0 |
109 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
110 | | CRC-16/CMS | Crc16Cms | 16 | 0x8005 | 0xFFFF | False | False | 0x0 | 0xAEE7 | 0x0 |
111 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
112 | | CRC-16/DDS-110 | Crc16Dds110 | 16 | 0x8005 | 0x800D | False | False | 0x0 | 0x9ECF | 0x0 |
113 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
114 | | CRC-16/DECT-R | Crc16DectR | 16 | 0x589 | 0x0 | False | False | 0x1 | 0x7E | 0x589 |
115 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
116 | | CRC-16/DECT-X | Crc16DectX | 16 | 0x589 | 0x0 | False | False | 0x0 | 0x7F | 0x0 |
117 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
118 | | CRC-16/DNP | Crc16Dnp | 16 | 0x3D65 | 0x0 | True | True | 0xFFFF | 0xEA82 | 0x66C5 |
119 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
120 | | CRC-16/EN-13757 | Crc16En13757 | 16 | 0x3D65 | 0x0 | False | False | 0xFFFF | 0xC2B7 | 0xA366 |
121 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
122 | | CRC-16/GENIBUS | Crc16Genibus | 16 | 0x1021 | 0xFFFF | False | False | 0xFFFF | 0xD64E | 0x1D0F |
123 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
124 | | CRC-16/GSM | Crc16Gsm | 16 | 0x1021 | 0x0 | False | False | 0xFFFF | 0xCE3C | 0x1D0F |
125 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
126 | | CRC-16/IBM-3740 | Crc16Ibm3740 | 16 | 0x1021 | 0xFFFF | False | False | 0x0 | 0x29B1 | 0x0 |
127 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
128 | | CRC-16/IBM-SDLC | Crc16IbmSdlc | 16 | 0x1021 | 0xFFFF | True | True | 0xFFFF | 0x906E | 0xF0B8 |
129 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
130 | | CRC-16/ISO-IEC-14443-3-A | Crc16IsoIec144433A | 16 | 0x1021 | 0xC6C6 | True | True | 0x0 | 0xBF05 | 0x0 |
131 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
132 | | CRC-16/KERMIT | Crc16Kermit | 16 | 0x1021 | 0x0 | True | True | 0x0 | 0x2189 | 0x0 |
133 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
134 | | CRC-16/LJ1200 | Crc16Lj1200 | 16 | 0x6F63 | 0x0 | False | False | 0x0 | 0xBDF4 | 0x0 |
135 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
136 | | CRC-16/M17 | Crc16M17 | 16 | 0x5935 | 0xFFFF | False | False | 0x0 | 0x772B | 0x0 |
137 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
138 | | CRC-16/MAXIM-DOW | Crc16MaximDow | 16 | 0x8005 | 0x0 | True | True | 0xFFFF | 0x44C2 | 0xB001 |
139 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
140 | | CRC-16/MCRF4XX | Crc16Mcrf4Xx | 16 | 0x1021 | 0xFFFF | True | True | 0x0 | 0x6F91 | 0x0 |
141 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
142 | | CRC-16/MODBUS | Crc16Modbus | 16 | 0x8005 | 0xFFFF | True | True | 0x0 | 0x4B37 | 0x0 |
143 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
144 | | CRC-16/NRSC-5 | Crc16Nrsc5 | 16 | 0x80B | 0xFFFF | True | True | 0x0 | 0xA066 | 0x0 |
145 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
146 | | CRC-16/OPENSAFETY-A | Crc16OpensafetyA | 16 | 0x5935 | 0x0 | False | False | 0x0 | 0x5D38 | 0x0 |
147 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
148 | | CRC-16/OPENSAFETY-B | Crc16OpensafetyB | 16 | 0x755B | 0x0 | False | False | 0x0 | 0x20FE | 0x0 |
149 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
150 | | CRC-16/PROFIBUS | Crc16Profibus | 16 | 0x1DCF | 0xFFFF | False | False | 0xFFFF | 0xA819 | 0xE394 |
151 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
152 | | CRC-16/RIELLO | Crc16Riello | 16 | 0x1021 | 0xB2AA | True | True | 0x0 | 0x63D0 | 0x0 |
153 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
154 | | CRC-16/SPI-FUJITSU | Crc16SpiFujitsu | 16 | 0x1021 | 0x1D0F | False | False | 0x0 | 0xE5CC | 0x0 |
155 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
156 | | CRC-16/T10-DIF | Crc16T10Dif | 16 | 0x8BB7 | 0x0 | False | False | 0x0 | 0xD0DB | 0x0 |
157 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
158 | | CRC-16/TELEDISK | Crc16Teledisk | 16 | 0xA097 | 0x0 | False | False | 0x0 | 0xFB3 | 0x0 |
159 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
160 | | CRC-16/TMS37157 | Crc16Tms37157 | 16 | 0x1021 | 0x89EC | True | True | 0x0 | 0x26B1 | 0x0 |
161 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
162 | | CRC-16/UMTS | Crc16Umts | 16 | 0x8005 | 0x0 | False | False | 0x0 | 0xFEE8 | 0x0 |
163 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
164 | | CRC-16/USB | Crc16Usb | 16 | 0x8005 | 0xFFFF | True | True | 0xFFFF | 0xB4C8 | 0xB001 |
165 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
166 | | CRC-16/XMODEM | Crc16Xmodem | 16 | 0x1021 | 0x0 | False | False | 0x0 | 0x31C3 | 0x0 |
167 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
168 | | CRC-17/CAN-FD | Crc17CanFd | 17 | 0x1685B | 0x0 | False | False | 0x0 | 0x4F03 | 0x0 |
169 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
170 | | CRC-21/CAN-FD | Crc21CanFd | 21 | 0x102899 | 0x0 | False | False | 0x0 | 0xED841 | 0x0 |
171 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
172 | | CRC-24/BLE | Crc24Ble | 24 | 0x65B | 0x555555 | True | True | 0x0 | 0xC25A56 | 0x0 |
173 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
174 | | CRC-24/FLEXRAY-A | Crc24FlexrayA | 24 | 0x5D6DCB | 0xFEDCBA | False | False | 0x0 | 0x7979BD | 0x0 |
175 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
176 | | CRC-24/FLEXRAY-B | Crc24FlexrayB | 24 | 0x5D6DCB | 0xABCDEF | False | False | 0x0 | 0x1F23B8 | 0x0 |
177 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
178 | | CRC-24/INTERLAKEN | Crc24Interlaken | 24 | 0x328B63 | 0xFFFFFF | False | False | 0xFFFFFF | 0xB4F3E6 | 0x144E63 |
179 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
180 | | CRC-24/LTE-A | Crc24LteA | 24 | 0x864CFB | 0x0 | False | False | 0x0 | 0xCDE703 | 0x0 |
181 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
182 | | CRC-24/LTE-B | Crc24LteB | 24 | 0x800063 | 0x0 | False | False | 0x0 | 0x23EF52 | 0x0 |
183 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
184 | | CRC-24/OPENPGP | Crc24Openpgp | 24 | 0x864CFB | 0xB704CE | False | False | 0x0 | 0x21CF02 | 0x0 |
185 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
186 | | CRC-24/OS-9 | Crc24Os9 | 24 | 0x800063 | 0xFFFFFF | False | False | 0xFFFFFF | 0x200FA5 | 0x800FE3 |
187 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
188 | | CRC-30/CDMA | Crc30Cdma | 30 | 0x2030B9C7 | 0x3FFFFFFF | False | False | 0x3FFFFFFF | 0x4C34ABF | 0x34EFA55A |
189 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
190 | | CRC-31/PHILIPS | Crc31Philips | 31 | 0x4C11DB7 | 0x7FFFFFFF | False | False | 0x7FFFFFFF | 0xCE9E46C | 0x4EAF26F1 |
191 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
192 | | CRC-32/AIXM | Crc32Aixm | 32 | 0x814141AB | 0x0 | False | False | 0x0 | 0x3010BF7F | 0x0 |
193 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
194 | | CRC-32/AUTOSAR | Crc32Autosar | 32 | 0xF4ACFB13 | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0x1697D06A | 0x904CDDBF |
195 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
196 | | CRC-32/BASE91-D | Crc32Base91D | 32 | 0xA833982B | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0x87315576 | 0x45270551 |
197 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
198 | | CRC-32/BZIP2 | Crc32Bzip2 | 32 | 0x4C11DB7 | 0xFFFFFFFF | False | False | 0xFFFFFFFF | 0xFC891918 | 0xC704DD7B |
199 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
200 | | CRC-32/CD-ROM-EDC | Crc32CdRomEdc | 32 | 0x8001801B | 0x0 | True | True | 0x0 | 0x6EC2EDC4 | 0x0 |
201 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
202 | | CRC-32/CKSUM | Crc32Cksum | 32 | 0x4C11DB7 | 0x0 | False | False | 0xFFFFFFFF | 0x765E7680 | 0xC704DD7B |
203 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
204 | | CRC-32/ISCSI | Crc32Iscsi | 32 | 0x1EDC6F41 | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0xE3069283 | 0xB798B438 |
205 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
206 | | CRC-32/ISO-HDLC | Crc32IsoHdlc | 32 | 0x4C11DB7 | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0xCBF43926 | 0xDEBB20E3 |
207 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
208 | | CRC-32/JAMCRC | Crc32Jamcrc | 32 | 0x4C11DB7 | 0xFFFFFFFF | True | True | 0x0 | 0x340BC6D9 | 0x0 |
209 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
210 | | CRC-32/MEF | Crc32Mef | 32 | 0x741B8CD7 | 0xFFFFFFFF | True | True | 0x0 | 0xD2C22F51 | 0x0 |
211 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
212 | | CRC-32/MPEG-2 | Crc32Mpeg2 | 32 | 0x4C11DB7 | 0xFFFFFFFF | False | False | 0x0 | 0x376E6E7 | 0x0 |
213 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
214 | | CRC-32/XFER | Crc32Xfer | 32 | 0xAF | 0x0 | False | False | 0x0 | 0xBD0BE338 | 0x0 |
215 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
216 | | CRC-40/GSM | Crc40Gsm | 40 | 0x4820009 | 0x0 | False | False | 0xFFFFFFFFFF | 0xD4164FC646 | 0xC4FF8071FF |
217 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
218 | | CRC-64/ECMA-182 | Crc64Ecma182 | 64 | 0x42F0E1EBA9EA3693 | 0x0 | False | False | 0x0 | 0x6C40DF5F0B497347 | 0x0 |
219 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
220 | | CRC-64/GO-ISO | Crc64GoIso | 64 | 0x1B | 0xFFFFFFFFFFFFFFFF | True | True | 0xFFFFFFFFFFFFFFFF | 0xB90956C775A41001 | 0x5300000000000000 |
221 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
222 | | CRC-64/MS | Crc64Ms | 64 | 0x259C84CBA6426349 | 0xFFFFFFFFFFFFFFFF | True | True | 0x0 | 0x75D4B74F024ECEEA | 0x0 |
223 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
224 | | CRC-64/NVME | Crc64Nvme | 64 | 0xAD93D23594C93659 | 0xFFFFFFFFFFFFFFFF | True | True | 0xFFFFFFFFFFFFFFFF | 0xAE8B14860A799888 | 0xF310303B2B6F6E42 |
225 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
226 | | CRC-64/REDIS | Crc64Redis | 64 | 0xAD93D23594C935A9 | 0x0 | True | True | 0x0 | 0xE9C6D914C4B8D9CA | 0x0 |
227 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
228 | | CRC-64/WE | Crc64We | 64 | 0x42F0E1EBA9EA3693 | 0xFFFFFFFFFFFFFFFF | False | False | 0xFFFFFFFFFFFFFFFF | 0x62EC59E3F1A4F00A | 0xFCACBEBD5931A992 |
229 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
230 | | CRC-64/XZ | Crc64Xz | 64 | 0x42F0E1EBA9EA3693 | 0xFFFFFFFFFFFFFFFF | True | True | 0xFFFFFFFFFFFFFFFF | 0x995DC9BBDF1939FA | 0x49958C9ABD7D353F |
231 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
232 | | CRC-82/DARC | Crc82Darc | 82 | 0x308C0111011401440411 | 0x0 | True | True | 0x0 | 0x9EA83F625023801FD612 | 0x0 |
233 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+
234 |
235 |
236 | Aliases
237 | -------
238 |
239 | As some CRCs are also known under different names aliases for the CRC classes are defined.
240 |
241 |
242 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
243 | | CRC | Class | Alias | Alias Classes |
244 | +==========================+====================+=====================================================================+==============================================================+
245 | | CRC-4/G-704 | Crc4G704 | CRC-4/ITU | Crc4Itu |
246 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
247 | | CRC-5/EPC-C1G2 | Crc5EpcC1G2 | CRC-5/EPC | Crc5Epc |
248 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
249 | | CRC-5/G-704 | Crc5G704 | CRC-5/ITU | Crc5Itu |
250 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
251 | | CRC-6/G-704 | Crc6G704 | CRC-6/ITU | Crc6Itu |
252 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
253 | | CRC-7/MMC | Crc7Mmc | CRC-7 | Crc7 |
254 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
255 | | CRC-8/I-432-1 | Crc8I4321 | CRC-8/ITU | Crc8Itu |
256 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
257 | | CRC-8/MAXIM-DOW | Crc8MaximDow | CRC-8/MAXIM, DOW-CRC | Crc8Maxim, CrcDow |
258 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
259 | | CRC-8/SMBUS | Crc8Smbus | CRC-8 | Crc8 |
260 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
261 | | CRC-8/TECH-3250 | Crc8Tech3250 | CRC-8/AES, CRC-8/EBU | Crc8Aes, Crc8Ebu |
262 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
263 | | CRC-10/ATM | Crc10Atm | CRC-10, CRC-10/I-610 | Crc10, Crc10I610 |
264 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
265 | | CRC-11/FLEXRAY | Crc11Flexray | CRC-11 | Crc11 |
266 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
267 | | CRC-12/DECT | Crc12Dect | CRC-12-X | Crc12X |
268 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
269 | | CRC-12/UMTS | Crc12Umts | CRC-12/3GPP | Crc123Gpp |
270 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
271 | | CRC-15/CAN | Crc15Can | CRC-15 | Crc15 |
272 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
273 | | CRC-16/ARC | Crc16Arc | ARC, CRC-16/LHA, CRC-IBM | CrcArc, Crc16Lha, CrcIbm |
274 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
275 | | CRC-16/DECT-R | Crc16DectR | R-CRC-16 | Crc16R |
276 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
277 | | CRC-16/DECT-X | Crc16DectX | X-CRC-16 | Crc16X |
278 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
279 | | CRC-16/GENIBUS | Crc16Genibus | CRC-16/DARC, CRC-16/EPC, CRC-16/EPC-C1G2, CRC-16/I-CODE | Crc16Darc, Crc16Epc, Crc16EpcC1G2, Crc16ICode |
280 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
281 | | CRC-16/IBM-3740 | Crc16Ibm3740 | CRC-16/AUTOSAR, CRC-16/CCITT-FALSE | Crc16Autosar, Crc16CcittFalse |
282 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
283 | | CRC-16/IBM-SDLC | Crc16IbmSdlc | CRC-16/ISO-HDLC, CRC-16/ISO-IEC-14443-3-B, CRC-16/X-25, CRC-B, X-25 | Crc16IsoHdlc, Crc16IsoIec144433B, Crc16X25, CrcB, CrcX25 |
284 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
285 | | CRC-16/ISO-IEC-14443-3-A | Crc16IsoIec144433A | CRC-A | CrcA |
286 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
287 | | CRC-16/KERMIT | Crc16Kermit | CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/V-41-LSB, CRC-CCITT, KERMIT | Crc16Ccitt, Crc16CcittTrue, Crc16V41Lsb, CrcCcitt, CrcKermit |
288 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
289 | | CRC-16/MAXIM-DOW | Crc16MaximDow | CRC-16/MAXIM | Crc16Maxim |
290 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
291 | | CRC-16/MODBUS | Crc16Modbus | MODBUS | CrcModbus |
292 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
293 | | CRC-16/PROFIBUS | Crc16Profibus | CRC-16/IEC-61158-2 | Crc16Iec611582 |
294 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
295 | | CRC-16/SPI-FUJITSU | Crc16SpiFujitsu | CRC-16/AUG-CCITT | Crc16AugCcitt |
296 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
297 | | CRC-16/UMTS | Crc16Umts | CRC-16/BUYPASS, CRC-16/VERIFONE | Crc16Buypass, Crc16Verifone |
298 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
299 | | CRC-16/XMODEM | Crc16Xmodem | CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM | Crc16Acorn, Crc16Lte, Crc16V41Msb, CrcXmodem, CrcZmodem |
300 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
301 | | CRC-24/OPENPGP | Crc24Openpgp | CRC-24 | Crc24 |
302 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
303 | | CRC-32/AIXM | Crc32Aixm | CRC-32Q | Crc32Q |
304 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
305 | | CRC-32/BASE91-D | Crc32Base91D | CRC-32D | Crc32D |
306 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
307 | | CRC-32/BZIP2 | Crc32Bzip2 | CRC-32/AAL5, CRC-32/DECT-B, B-CRC-32 | Crc32Aal5, Crc32DectB, Crc32B |
308 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
309 | | CRC-32/CKSUM | Crc32Cksum | CKSUM, CRC-32/POSIX | CrcCksum, Crc32Posix |
310 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
311 | | CRC-32/ISCSI | Crc32Iscsi | CRC-32/BASE91-C, CRC-32/CASTAGNOLI, CRC-32/INTERLAKEN, CRC-32C | Crc32Base91C, Crc32Castagnoli, Crc32Interlaken, Crc32C |
312 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
313 | | CRC-32/ISO-HDLC | Crc32IsoHdlc | CRC-32, CRC-32/ADCCP, CRC-32/V-42, CRC-32/XZ, PKZIP | Crc32, Crc32Adccp, Crc32V42, Crc32Xz, CrcPkzip |
314 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
315 | | CRC-32/JAMCRC | Crc32Jamcrc | JAMCRC | CrcJamcrc |
316 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
317 | | CRC-32/XFER | Crc32Xfer | XFER | CrcXfer |
318 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
319 | | CRC-64/ECMA-182 | Crc64Ecma182 | CRC-64 | Crc64 |
320 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
321 | | CRC-64/XZ | Crc64Xz | CRC-64/GO-ECMA | Crc64GoEcma |
322 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+
323 |
--------------------------------------------------------------------------------