pax_global_header00006660000000000000000000000064143220762670014523gustar00rootroot0000000000000052 comment=92da616bb12c7fbefbe239bd013fc03c3bf8c4c4 crccheck-1.3.0/000077500000000000000000000000001432207626700132715ustar00rootroot00000000000000crccheck-1.3.0/.coveragerc000066400000000000000000000014431432207626700154140ustar00rootroot00000000000000# .coveragerc to control coverage.py [run] branch = True omit = *mock*, *pbr*, *six*, *funcsigs*, *encodings* [report] # Regexes for lines to exclude from consideration exclude_lines = # Have to re-enable the standard pragma pragma: no cover # Ignore backward compatibility code if sys.version_info < (3, 3, 0): # Don't complain about missing debug-only code: def __repr__ if self\.debug # Don't complain if tests don't hit defensive assertion code: raise AssertionError raise NotImplementedError # Don't complain if non-runnable code isn't run: if 0: if __name__ == .__main__.: mock pbr six omit = tests/__init__.py tests/* ignore_errors = True [html] directory = coverage_html_reportcrccheck-1.3.0/.gitignore000066400000000000000000000001011432207626700152510ustar00rootroot00000000000000.coverage .idea /build /dist *.pyc /crccheck.egg-info docs/build crccheck-1.3.0/.idea/000077500000000000000000000000001432207626700142515ustar00rootroot00000000000000crccheck-1.3.0/.idea/.name000066400000000000000000000000101432207626700151610ustar00rootroot00000000000000crccheckcrccheck-1.3.0/.idea/crccheck.iml000066400000000000000000000023011432207626700165150ustar00rootroot00000000000000 crccheck-1.3.0/.idea/inspectionProfiles/000077500000000000000000000000001432207626700201305ustar00rootroot00000000000000crccheck-1.3.0/.idea/inspectionProfiles/Project_Default.xml000066400000000000000000000010671432207626700237300ustar00rootroot00000000000000 crccheck-1.3.0/.idea/inspectionProfiles/profiles_settings.xml000066400000000000000000000003611432207626700244150ustar00rootroot00000000000000 crccheck-1.3.0/.idea/misc.xml000066400000000000000000000002711432207626700157260ustar00rootroot00000000000000 crccheck-1.3.0/.idea/modules.xml000066400000000000000000000004141432207626700164420ustar00rootroot00000000000000 crccheck-1.3.0/LICENSE.txt000066400000000000000000000021161432207626700151140ustar00rootroot00000000000000MIT License Copyright (c) 2015-2022 Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. crccheck-1.3.0/Makefile000066400000000000000000000043571432207626700147420ustar00rootroot00000000000000################################################################################################### # License: # MIT License # # Copyright (c) 2015-2022 by Martin Scharrer # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software # and associated documentation files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or # substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ################################################################################################### .PHONY: all test Install plugins dist clean doc release all: test test: @echo ""; echo "Running tests:" @python -m coverage run --branch -m unittest discover @python -m coverage report @python -m coverage html coverage: test dist: @python setup.py test sdist bdist_wheel clean: @${RM} -rf dist bdist build */__pycache__ */*.pyc *.egg-info coverage_html_report doc: @echo ""; echo "Extracting documentation:" @cd docs/; export PYTHONPATH=..; python ../create/crctable.py > source/crctable.rst @cd docs/; sphinx-apidoc -f -o source ../crccheck @cd docs/; sphinx-build -b html source build update: @test -z "$$(git status --porcelain crccheck/crc.py)" || (echo "crccheck/crc.py has uncommitted changes. Aborting!" && exit 1) @cd create/; python dl.py > ../crccheck/crc.py @test -z "$$(git status --porcelain crccheck/crc.py)" || echo "crccheck/crc.py has been updated." release: clean test doc dist crccheck-1.3.0/README.rst000066400000000000000000000104441432207626700147630ustar00rootroot00000000000000crccheck - Classes to calculate CRCs and checksums from binary data =================================================================== The ``crccheck.crc`` module implements all CRCs listed in the `Catalogue of parametrised CRC algorithms `_: 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, 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, 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, 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, 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, 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, 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, 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, CRC-16/KERMIT, CRC-16/LJ1200, CRC-16/M17, CRC-16/MAXIM-DOW, CRC-16/MCRF4XX, CRC-16/MODBUS, CRC-16/NRSC-5, CRC-16/OPENSAFETY-A, CRC-16/OPENSAFETY-B, CRC-16/PROFIBUS, CRC-16/RIELLO, CRC-16/SPI-FUJITSU, CRC-16/T10-DIF, 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, 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, CRC-30/CDMA, CRC-31/PHILIPS, CRC-32/AIXM, CRC-32/AUTOSAR, CRC-32/BASE91-D, CRC-32/BZIP2, CRC-32/CD-ROM-EDC, 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, CRC-64/ECMA-182, CRC-64/GO-ISO, CRC-64/MS, CRC-64/REDIS, CRC-64/WE, CRC-64/XZ, CRC-82/DARC For the class names simply remove all dashes and slashes from the above names and apply CamelCase, e.g. "CRC-32/MPEG-2" is implemented by ``Crc32Mpeg2``. Other CRC can be calculated by using the general class ``crccheck.crc.Crc`` by providing all required CRC parameters. The ``crccheck.checksum`` module implements additive and XOR checksums with 8, 16 and 32 bit: ``Checksum8``, ``Checksum16``, ``Checksum32`` and ``ChecksumXor8``, ``ChecksumXor16``, ``ChecksumXor32`` Usage example:: from crccheck.crc import Crc32, CrcXmodem from crccheck.checksum import Checksum32 # Quick calculation data = bytearray.fromhex("DEADBEEF") crc = Crc32.calc(data) checksum = Checksum32.calc(data) # Procsss multiple data buffers data1 = b"Binary string" # or use .encode(..) on normal sring - Python 3 only data2 = bytes.fromhex("1234567890") # Python 3 only, use bytearray for older versions data3 = (0x0, 255, 12, 99) # Iterable which returns ints in byte range (0..255) crcinst = CrcXmodem() crcinst.process(data1) crcinst.process(data2) crcinst.process(data3[1:-1]) crcbytes = crcinst.finalbytes() crchex = crcinst.finalhex() crcint = crcinst.final() License: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.crccheck-1.3.0/crccheck/000077500000000000000000000000001432207626700150365ustar00rootroot00000000000000crccheck-1.3.0/crccheck/__init__.py000066400000000000000000000126251432207626700171550ustar00rootroot00000000000000""" Classes to calculate CRCs and checksums from binary data ======================================================== The :mod:`crccheck.crc` module implements all CRCs listed in the `Catalogue of parametrised CRC algorithms `_: 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, 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, 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, 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, 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, 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, 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, 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, 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, CRC-16/GENIBUS, CRC-16/DARC, CRC-16/EPC, CRC-16/EPC-C1G2, CRC-16/I-CODE, CRC-16/GSM, CRC-16/IBM-3740, 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, 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, KERMIT, CRC-16/LJ1200, CRC-16/MAXIM-DOW, CRC-16/MAXIM, CRC-16/MCRF4XX, CRC-16/MODBUS, MODBUS, CRC-16/NRSC-5, CRC-16/OPENSAFETY-A, CRC-16/OPENSAFETY-B, CRC-16/PROFIBUS, CRC-16/IEC-61158-2, CRC-16/RIELLO, CRC-16/SPI-FUJITSU, CRC-16/AUG-CCITT, CRC-16/T10-DIF, CRC-16/TELEDISK, CRC-16/TMS37157, CRC-16/UMTS, CRC-16/BUYPASS, CRC-16/VERIFONE, 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, 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, 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, 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, CRC-32/ISCSI, CRC-32/BASE91-C, CRC-32/CASTAGNOLI, CRC-32/INTERLAKEN, CRC-32C, CRC-32/ISO-HDLC, CRC-32, 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, CRC-64/ECMA-182, CRC-64, CRC-64/GO-ISO, CRC-64/WE, CRC-64/XZ, CRC-64/GO-ECMA, CRC-82/DARC. For the class names simply remove all dashes and slashes from the above names and apply CamelCase, e.g. "CRC-32/MPEG-2" is implemented by :class:`.Crc32Mpeg2`. Other CRC can be calculated by using the general class :class:`crccheck.crc.Crc` by providing all required CRC parameters. The :mod:`crccheck.checksum` module implements additive and XOR checksums with 8, 16 and 32 bit: :class:`.Checksum8`, :class:`.Checksum16`, :class:`.Checksum32` and :class:`.ChecksumXor8`, :class:`.ChecksumXor16`, :class:`.ChecksumXor32`. Usage example:: from crccheck.crc import Crc32, CrcXmodem from crccheck.checksum import Checksum32 # Quick calculation data = bytearray.fromhex("DEADBEEF") crc = Crc32.calc(data) checksum = Checksum32.calc(data) # Procsss multiple data buffers data1 = b"Binary string" # or use .encode(..) on normal sring - Python 3 only data2 = bytes.fromhex("1234567890") # Python 3 only, use bytearray for older versions data3 = (0x0, 255, 12, 99) # Iterable which returns ints in byte range (0..255) crcinst = CrcXmodem() crcinst.process(data1) crcinst.process(data2) crcinst.process(data3[1:-1]) crcbytes = crcinst.finalbytes() crchex = crcinst.finalhex() crcint = crcinst.final() License: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from crccheck import crc, checksum crccheck-1.3.0/crccheck/base.py000066400000000000000000000220031432207626700163170ustar00rootroot00000000000000""" Base class for CRC and checksum classes. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import math REFLECT_BIT_ORDER_TABLE = ( 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, ) def reflectbitorder(width, value): """ Reflects the bit order of the given value according to the given bit width. Args: width (int): bitwidth value (int): value to reflect """ binstr = ("0" * width + bin(value)[2:])[-width:] return int(binstr[::-1], 2) class CrccheckError(Exception): """General checksum error exception""" pass class CrccheckBase(object): """ Abstract base class for checksumming classes. Args: initvalue (int): Initial value. If None then the default value for the class is used. """ _initvalue = 0x00 _check_result = None _check_data = None _file_chunksize = 512 _width = 0 def __init__(self, initvalue=None): if initvalue is None: self._value = self._initvalue else: self._value = initvalue def reset(self, value=None): """ Reset instance. Resets the instance state to the initial value. This is not required for a just created instance. Args: value (int): Set internal value. If None then the default initial value for the class is used. Returns: self """ if value is None: self._value = self._initvalue else: self._value = value return self def process(self, data): """ Process given data. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. Returns: self """ raise NotImplementedError def final(self): """Return final check value. The internal state is not modified by this so further data can be processed afterwards. Return: int: final value """ return self._value def finalhex(self, byteorder='big'): """Return final checksum value as hexadecimal string (without leading "0x"). The hex value is zero padded to bitwidth/8. The internal state is not modified by this so further data can be processed afterwards. Return: str: final value as hex string without leading '0x'. """ asbytes = self.finalbytes(byteorder) try: # bytearray.hex() is new in Python 3.5 return asbytes.hex() except AttributeError: # pragma: no cover return "".join(["{:02x}".format(b) for b in asbytes]) def finalbytes(self, byteorder='big'): """Return final checksum value as bytes. The internal state is not modified by this so further data can be processed afterwards. Return: bytes: final value as bytes """ bytelength = int(math.ceil(self._width / 8.0)) asint = self.final() try: # int.to_bytes() is new in Python 3.2 return asint.to_bytes(bytelength, byteorder) except AttributeError: # pragma: no cover asbytes = bytearray(bytelength) for i in range(0, bytelength): asbytes[i] = asint & 0xFF asint >>= 8 if byteorder == 'big': asbytes.reverse() return asbytes def value(self): """Returns current intermediate value. Note that in general final() must be used to get the a final value. Return: int: current value """ return self._value @classmethod def calc(cls, data, initvalue=None, **kwargs): """ Fully calculate CRC/checksum over given data. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. initvalue (int): Initial value. If None then the default value for the class is used. Return: int: final value """ inst = cls(initvalue, **kwargs) inst.process(data) return inst.final() @classmethod def calchex(cls, data, initvalue=None, byteorder='big', **kwargs): """Fully calculate checksum over given data. Return result as hex string. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. initvalue (int): Initial value. If None then the default value for the class is used. byteorder ('big' or 'little'): order (endianness) of returned bytes. Return: str: final value as hex string without leading '0x'. """ inst = cls(initvalue, **kwargs) inst.process(data) return inst.finalhex(byteorder) @classmethod def calcbytes(cls, data, initvalue=None, byteorder='big', **kwargs): """Fully calculate checksum over given data. Return result as bytearray. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. initvalue (int): Initial value. If None then the default value for the class is used. byteorder ('big' or 'little'): order (endianness) of returned bytes. Return: bytes: final value as bytes """ inst = cls(initvalue, **kwargs) inst.process(data) return inst.finalbytes(byteorder) @classmethod def selftest(cls, data=None, expectedresult=None, **kwargs): """ Selftest method for automated tests. Args: data (bytes, bytearray or list of int [0-255]): data to process expectedresult (int): expected result Raises: CrccheckError: if result is not as expected """ if data is None: data = cls._check_data expectedresult = cls._check_result result = cls.calc(data, **kwargs) if result != expectedresult: raise CrccheckError("{:s}: expected {:s}, got {:s}".format(cls.__name__, hex(expectedresult), hex(result))) crccheck-1.3.0/crccheck/checksum.py000066400000000000000000000176701432207626700172250ustar00rootroot00000000000000""" Classes to calculated additive and XOR checksums. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from crccheck.base import CrccheckBase, CrccheckError class ChecksumBase(CrccheckBase): """ Base class for all checksum classes. Args: initvalue (int): Initial value. If None then the default value for the class is used. byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes. """ _width = 0 _mask = 0 _check_data = (0xDE, 0xAD, 0xBE, 0xEF, 0xAA, 0x55, 0xC2, 0x8C) _check_result_littleendian = None def __init__(self, initvalue=0, byteorder='big'): super(ChecksumBase, self).__init__(initvalue) self._byteorder = byteorder def process(self, data): """ Process given data. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. Returns: self """ dataword = 0 n = 0 bigendian = (self._byteorder == 'big') width = self._width mask = self._mask value = self._value for byte in data: if bigendian: dataword = (dataword << 8) | byte else: dataword |= (byte << n) n += 8 if n == width: value = mask & (value + dataword) dataword = 0 n = 0 self._value = value return self @classmethod def selftest(cls, data=None, expectedresult=None, byteorder='big'): """ Selftest method for automated tests. Args: data (bytes, bytearray or list of int [0-255]): data to process expectedresult (int): expected result byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes. Raises: CrccheckError: if result is not as expected """ if data is None: data = cls._check_data if expectedresult is None: if byteorder == 'big': expectedresult = cls._check_result else: expectedresult = cls._check_result_littleendian result = cls.calc(data, byteorder=byteorder) if result != expectedresult: raise CrccheckError(hex(result)) class Checksum32(ChecksumBase): """ 32-bit checksum. Calculates 32-bit checksum by adding the input bytes in groups of four. Input data length must be a multiple of four, otherwise the last bytes are not used. """ _width = 32 _mask = 0xFFffFFff _check_result = 0x8903817B _check_result_littleendian = 0x7C810388 class Checksum16(ChecksumBase): """ 16-bit checksum. Calculates 16-bit checksum by adding the input bytes in groups of two. Input data length must be a multiple of two, otherwise the last byte is not used. """ _width = 16 _mask = 0xFFff _check_result = 0x0A7D _check_result_littleendian = 0x8008 class Checksum8(ChecksumBase): """ 8-bit checksum. Calculates 8-bit checksum by adding the input bytes. """ _width = 8 _mask = 0xFF _check_result = 0x85 _check_result_littleendian = _check_result class ChecksumXorBase(ChecksumBase): """ Base class for all XOR checksum classes. """ def process(self, data): """ Process given data. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. Returns: self """ dataword = 0 n = 0 bigendian = (self._byteorder == 'big') width = self._width mask = self._mask value = self._value for byte in data: if bigendian: dataword = (dataword << 8) | byte else: dataword |= (byte << n) n += 8 if n == width: value = mask & (value ^ dataword) dataword = 0 n = 0 self._value = value return self class ChecksumXor32(ChecksumXorBase): """ 32-bit XOR checksum. Calculates 32-bit checksum by XOR-ing the input bytes in groups of four. Input data length must be a multiple of four, otherwise the last bytes are not used. """ _width = 32 _mask = 0xFFffFFff _check_result = 0x74F87C63 _check_result_littleendian = 0x637CF874 class ChecksumXor16(ChecksumXorBase): """ 16-bit XOR checksum. Calculates 16-bit checksum by XOR-ing the input bytes in groups of two. Input data length must be a multiple of two, otherwise the last byte is not used. """ _width = 16 _mask = 0xFFff _check_result = 0x089B _check_result_littleendian = 0x9B08 class ChecksumXor8(ChecksumXorBase): """ 8-bit XOR checksum. Calculates 8-bit checksum by XOR-ing the input bytes. """ _width = 8 _mask = 0xFF _check_result = 0x93 _check_result_littleendian = _check_result class Checksum(ChecksumBase): """ General additive checksum. Args: width (int): bit width of checksum. Must be positive and a multiple of 8. initvalue (int): Initial value. If None then the default value for the class is used. byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes. """ _check_result = None _check_result_littleendian = None def __init__(self, width, initvalue=0, byteorder='big'): super(Checksum, self).__init__(initvalue, byteorder) width = int(width) if width <= 0 or width % 8 != 0: raise ValueError("width must be postive and a multiple of 8") self._width = width self._mask = (1 << width) - 1 class ChecksumXor(ChecksumXorBase): """ General XOR checksum. Args: width (int): bit width of checksum. Must be positive and a multiple of 8. initvalue (int): Initial value. If None then the default value for the class is used. byteorder ('big' or 'little'): byte order (endianness) used when reading the input bytes. """ _check_result = None _check_result_littleendian = None def __init__(self, width, initvalue=0, byteorder='big'): super(ChecksumXor, self).__init__(initvalue, byteorder) width = int(width) if width <= 0 or width % 8 != 0: raise ValueError("width must be postive and a multiple of 8") self._width = width self._mask = (1 << width) - 1 ALLCHECKSUMCLASSES = ( Checksum8, Checksum16, Checksum32, ChecksumXor8, ChecksumXor16, ChecksumXor32, ) crccheck-1.3.0/crccheck/crc.py000066400000000000000000001555701432207626700161740ustar00rootroot00000000000000""" Classes to calculate CRCs (Cyclic Redundancy Check). License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from crccheck.base import CrccheckBase, reflectbitorder, REFLECT_BIT_ORDER_TABLE, CrccheckError class CrcBase(CrccheckBase): """Abstract base class for all Cyclic Redundancy Checks (CRC) checksums""" _names = () _width = 0 _poly = 0x00 _initvalue = 0x00 _reflect_input = False _reflect_output = False _xor_output = 0x00 _check_result = None _check_data = bytearray(b"123456789") _residue = None def process(self, data): """ Process given data. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. Returns: self """ crc = self._value highbit = 1 << (self._width - 1) mask = ((highbit - 1) << 1) | 0x1 # done this way to avoid overrun for 64-bit values poly = self._poly shift = self._width - 8 diff8 = -shift if diff8 > 0: # enlarge temporary to fit 8-bit mask = 0xFF crc <<= diff8 shift = 0 highbit = 0x80 poly = self._poly << diff8 reflect = self._reflect_input for byte in data: if reflect: byte = REFLECT_BIT_ORDER_TABLE[byte] crc ^= (byte << shift) for i in range(0, 8): if crc & highbit: crc = (crc << 1) ^ poly else: crc = (crc << 1) crc &= mask if diff8 > 0: crc >>= diff8 self._value = crc return self def final(self): """ Return final CRC value. Return: int: final CRC value """ crc = self._value if self._reflect_output: crc = reflectbitorder(self._width, crc) crc ^= self._xor_output return crc def __eq__(self, other): # noinspection PyProtectedMember return self._width == other._width and \ self._poly == other._poly and \ self._initvalue == other._initvalue and \ self._reflect_input == other._reflect_input and \ self._reflect_output == other._reflect_output and \ self._xor_output == other._xor_output def __repr__(self): residue = hex(self._residue) if self._residue is not None else 'None' check_result = hex(self._check_result) if self._check_result is not None else 'None' return ("Crc(width={:d}, poly=0x{:x}, initvalue=0x{:X}, reflect_input={!s:s}, reflect_output={!s:s}, " + "xor_output=0x{:x}, check_result={}, residue={})").format( self._width, self._poly, self._initvalue, self._reflect_input, self._reflect_output, self._xor_output, check_result, residue) def find(classes=None, width=None, poly=None, initvalue=None, reflect_input=None, reflect_output=None, xor_output=None, check_result=None, residue=None): """Find CRC classes which the matching properties. Args: classes (None or list): List of classes to search in. If None the list ALLCRCCLASSES will be used. width (None or int): number of bits of the CRC classes to find poly (None or int): polygon to find initvalue (None or int): initvalue to find reflect_input (None or bool): reflect_input to find reflect_output (None or bool): reflect_output to find xor_output (None or int): xor_output to find check_result (None or int): check_result to find residue (None or int): residue to find Returns: List of CRC classes with the selected properties. Examples: Find all CRC16 classes: $ find(width=16) Find all CRC32 classes with all-1 init value and XOR output: $ find(width=32, initvalue=0xFFFF, xor_output=0xFFFF) """ found = list() if classes is None: classes = ALLCRCCLASSES for cls in classes: if width is not None and width != cls._width: continue if poly is not None and poly != cls._poly: continue if initvalue is not None and initvalue != cls._initvalue: continue if reflect_input is not None and reflect_input != cls._reflect_input: continue if reflect_output is not None and reflect_output != cls._reflect_output: continue if xor_output is not None and xor_output != cls._xor_output: continue if check_result is not None and check_result != cls._check_result: continue if residue is not None and residue != cls._residue: continue found.append(cls) return found def identify(data, crc, width=None, classes=None, one=True): """ Identify the used CRC algorithm which was used to calculate the CRC from some data. This function can be used to identify a suitable CRC class if the exact CRC algorithm/parameters are not known, but a CRC value is known from some data. Note that this function can be quite time consuming on large data, especially if the given width is not known. Args: data (bytes): Data to compare with the `crc`. crc (int): Known CRC of the given `data`. width (int or None): Known bit width of given `crc`. Providing the width will speed up the identification of the CRC algorithm. classes (iterable or None): Listing of classes to check. If None then ALLCRCCLASSES is used. one (bool): If True then only the first found CRC class is retunred. Otherwise a list of all suitable CRC classes. Returns: If `one` is True: CRC class which instances produce the given CRC from the given data. If no CRC class could be found `None` is returned. If `one` is False: List of CRC classes which instances produce the given CRC from the given data. The list may be empty. """ if classes is None: classes = ALLCRCCLASSES if width is not None: classes = (cls for cls in classes if cls._width == width) found = [] for cls in classes: if cls().calc(data) == crc: if one: return cls found.append(cls) if one: return None return found class Crc(CrcBase): """ Creates a new general (user-defined) CRC calculator instance. Arguments: width (int): bit width of CRC. poly (int): polynomial of CRC with the top bit omitted. initvalue (int): initial value of internal running CRC value. Usually either 0 or (1< Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from crccheck.base import CrccheckBase, reflectbitorder, REFLECT_BIT_ORDER_TABLE, CrccheckError class CrcBase(CrccheckBase): """Abstract base class for all Cyclic Redundancy Checks (CRC) checksums""" _names = () _width = 0 _poly = 0x00 _initvalue = 0x00 _reflect_input = False _reflect_output = False _xor_output = 0x00 _check_result = None _check_data = bytearray(b"123456789") _residue = None def process(self, data): """ Process given data. Args: data (bytes, bytearray or list of ints [0-255]): input data to process. Returns: self """ crc = self._value highbit = 1 << (self._width - 1) mask = ((highbit - 1) << 1) | 0x1 # done this way to avoid overrun for 64-bit values poly = self._poly shift = self._width - 8 diff8 = -shift if diff8 > 0: # enlarge temporary to fit 8-bit mask = 0xFF crc <<= diff8 shift = 0 highbit = 0x80 poly = self._poly << diff8 reflect = self._reflect_input for byte in data: if reflect: byte = REFLECT_BIT_ORDER_TABLE[byte] crc ^= (byte << shift) for i in range(0, 8): if crc & highbit: crc = (crc << 1) ^ poly else: crc = (crc << 1) crc &= mask if diff8 > 0: crc >>= diff8 self._value = crc return self def final(self): """ Return final CRC value. Return: int: final CRC value """ crc = self._value if self._reflect_output: crc = reflectbitorder(self._width, crc) crc ^= self._xor_output return crc def __eq__(self, other): return self._width == other._width and \ self._poly == other._poly and \ self._initvalue == other._initvalue and \ self._reflect_input == other._reflect_input and \ self._reflect_output == other._reflect_output and \ self._xor_output == other._xor_output def __repr__(self): residue = hex(self._residue) if self._residue is not None else 'None' check_result = hex(self._check_result) if self._check_result is not None else 'None' return ("Crc(width={:d}, poly=0x{:x}, initvalue=0x{:X}, reflect_input={!s:s}, reflect_output={!s:s}, " + "xor_output=0x{:x}, check_result={}, residue={})").format( self._width, self._poly, self._initvalue, self._reflect_input, self._reflect_output, self._xor_output, check_result, residue) def find(classes=None, width=None, poly=None, initvalue=None, reflect_input=None, reflect_output=None, xor_output=None, check_result=None, residue=None): """Find CRC classes which the matching properties. Args: classes (None or list): List of classes to search in. If None the list ALLCRCCLASSES will be used. width (None or int): number of bits of the CRC classes to find poly (None or int): polygon to find initvalue (None or int): initvalue to find reflect_input (None or bool): reflect_input to find reflect_output (None or bool): reflect_output to find xor_output (None or int): xor_output to find check_result (None or int): check_result to find residue (None or int): residue to find Returns: List of CRC classes with the selected properties. Examples: Find all CRC16 classes: $ find(width=16) Find all CRC32 classes with all-1 init value and XOR output: $ find(width=32, initvalue=0xFFFF, xor_output=0xFFFF) """ found = list() if classes is None: classes = ALLCRCCLASSES for cls in classes: if width is not None and width != cls._width: continue if poly is not None and poly != cls._poly: continue if initvalue is not None and initvalue != cls._initvalue: continue if reflect_input is not None and reflect_input != cls._reflect_input: continue if reflect_output is not None and reflect_output != cls._reflect_output: continue if xor_output is not None and xor_output != cls._xor_output: continue if check_result is not None and check_result != cls._check_result: continue if residue is not None and residue != cls._residue: continue found.append(cls) return found def identify(data, crc, width=None, classes=None, one=True): """ Identify the used CRC algorithm which was used to calculate the CRC from some data. This function can be used to identify a suitable CRC class if the exact CRC algorithm/parameters are not known, but a CRC value is known from some data. Note that this function can be quite time consuming on large data, especially if the given width is not known. Args: data (bytes): Data to compare with the `crc`. crc (int): Known CRC of the given `data`. width (int or None): Known bit width of given `crc`. Providing the width will speed up the identification of the CRC algorithm. classes (iterable or None): Listing of classes to check. If None then ALLCRCCLASSES is used. one (bool): If True then only the first found CRC class is retunred. Otherwise a list of all suitable CRC classes. Returns: If `one` is True: CRC class which instances produce the given CRC from the given data. If no CRC class could be found `None` is returned. If `one` is False: List of CRC classes which instances produce the given CRC from the given data. The list may be empty. """ if classes is None: classes = ALLCRCCLASSES if width is not None: classes = (cls for cls in classes if cls._width == width) found = [] for cls in classes: if cls().calc(data) == crc: if one: return cls found.append(cls) if one: return None return found class Crc(CrcBase): """ Creates a new general (user-defined) CRC calculator instance. Arguments: width (int): bit width of CRC. poly (int): polynomial of CRC with the top bit omitted. initvalue (int): initial value of internal running CRC value. Usually either 0 or (1< maxlen: idx = line.rindex(', ', 0, maxlen) lines.append(indent + line[0:idx+1] + '\n') line = line[idx+2:] except ValueError: pass lines.append(indent + line + '\n') # append rest return lines def getclassname(strname): if strname in renames: return renames[strname] return strname.replace('-', ' ').replace('/', ' ').title().replace(' ', '') def getbaseclass(width): return {8: 'Crc8Base', 16: 'Crc16Base', 32: 'Crc32Base'}.get(int(width), 'CrcBase') if __name__ == "__main__": crcs = list() for url in urls: response = urllib.request.urlopen(url) data = response.read().decode('utf-8') for crc in rCRC.findall(data): crc = list(crc) crc[3] = crc[3].capitalize() crc[4] = crc[4].capitalize() crc.append(getbaseclass(crc[0])) crc.append(getclassname(crc[8])) crcs.append(crc) crcs.sort(key=lambda x: (int(x[0]), x[10])) with OutFile(sys.argv, 1) as outfh: crcallaliases = [] with open('crc_head.py', 'r') as infh: outfh.write(infh.read()) outfh.write('\n') for crc in crcs: name = crc[8] clsname = crc[10] othernames = aliases.get(name, ()) if othernames: aliasdoc = '\n\n Aliases: ' + (', '.join(othernames)) + '\n ' namelist = [name] namelist.extend(othernames) names = "'" + ("', '".join(namelist)) + "'" else: aliasdoc = '' names = "'" + name + "'," outfh.write(template.format(*crc, aliasdoc, names)) crcallaliases.append(clsname) if name in aliases: outfh.write('\n') for alias in aliases.get(name, ()): clsalias = getclassname(alias) outfh.write('{} = {}\n'.format(clsalias, clsname)) crcallaliases.append(clsalias) if name in extra_class_aliases: if name not in aliases: outfh.write('\n') for clsalias in extra_class_aliases.get(name, ()): outfh.write('{} = {}\n'.format(clsalias, clsname)) crcallaliases.append(clsalias) if name in aliases or name in extra_class_aliases: outfh.write('\n') allcls = ", ".join(crc[10] for crc in crcs) lines = ['\n', 'ALLCRCCLASSES = (\n'] lines.extend(linejoin(allcls, 120, ' ' * 4)) lines.append(')\n') allclsalias = ", ".join(crcallaliases) lines.extend(['\n', 'ALLCRCCLASSES_ALIASES = (\n']) lines.extend(linejoin(allclsalias, 120, ' ' * 4)) lines.append(')\n') for line in lines: outfh.write(line) crccheck-1.3.0/docs/000077500000000000000000000000001432207626700142215ustar00rootroot00000000000000crccheck-1.3.0/docs/build.bat000066400000000000000000000002221432207626700160040ustar00rootroot00000000000000set PYTHONPATH=.. python ../create/crctable.py > source/crctable.rst sphinx-apidoc -f -o source ../crccheck sphinx-build -b html source build crccheck-1.3.0/docs/source/000077500000000000000000000000001432207626700155215ustar00rootroot00000000000000crccheck-1.3.0/docs/source/changelog.rst000066400000000000000000000035641432207626700202120ustar00rootroot00000000000000========= Changelog ========= v1.3.0 - 2022-10-13 =================== * Updated unit tests to use correct asserts. * Some code quality adjustments. * Switched license from GPLv3 to MIT. v1.2.0 - 2022-10-06 =================== * Updated with newest CRC from catalogue. * Changed project repository from Mercurial to Git. v1.1.1 - 2022-10-06 =================== * Switched unit tests from nose to unittest module. v1.1 - 2021-11-25 ================= * Fixed ignored byteorder in calchex(). * Updated documentation. v1.0 - 2020-09-21 ================= * Added further CRCs. * Fixed missing storage of initial value for general ``Crc`` class. Before ``reset()`` did not work correctly. * Updated tests to achieve 100% code coverage. v0.6 - 2016-04-03 ================= * Added compatibility with Python 2.7 and 3.3. v0.5 - 2016-03-30 ================= * Added general checksum classes Checksum and ChecksumXor. * changed ``process()`` to return ``self`` so that calls can be chained. * changed ``init()`` to return ``self`` so that calls can be chained. * renamed ``init()`` to ``reset()``. * Updated documentation. v0.4 - 2016-03-29 ================= * Removed arguments startindex and endindex as they are not required. * Optimized reflectbitorder(). * base: Added ``byteorder`` argument to ``calchex()``. * Removed outdated code. * Added more unit tests. v0.3 - 2016-03-28 ================= * Renamed package to ``crccheck`` as old name was taken in PIP. * Changed ``bigendian=True/False`` arguments to ``byteorder='big'/'little'``. * Added more docstring documentation. * Removed outdated code from repository. v0.2 - 2016-03-27 ================= * Changes to support Python 3. * Code reformatting. * Some smaller fixes. * Runtime optimisations. v0.1 - 2015-09-23 ================= * First version. crccheck-1.3.0/docs/source/conf.py000066400000000000000000000244331432207626700170260ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # crccheck documentation build configuration file, created by # sphinx-quickstart on Thu Apr 09 22:32:46 2015. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import os import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('../..')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'crccheck' copyright = u'2015-2020, Martin Scharrer' author = u'Martin Scharrer' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '1.3' # The full version, including alpha/beta/rc tags. release = '1.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = 'en' # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'classic' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. html_sidebars = { '**': ['globaltoc.html', 'searchbox.html'], 'using/windows': ['windowssidebar.html', 'searchbox.html'], } # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' #html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value #html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. #html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. htmlhelp_basename = 'crccheckdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', # Latex figure (float) alignment #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'crccheck.tex', u'crccheck Documentation', u'Martin Scharrer', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'crccheck', u'crccheck Documentation', [author], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'crccheck', u'crccheck Documentation', author, 'crccheck', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'https://docs.python.org/': None} autodoc_member_order='bysource' autodoc_default_flags = ['members', 'undoc-members', 'show-inheritance'] # [ 'members', 'undoc-members', 'private-members', 'special-members', 'inherited-members', 'show-inheritance'] # Napoleon settings napoleon_google_docstring = True napoleon_numpy_docstring = True napoleon_include_private_with_doc = False napoleon_include_special_with_doc = False napoleon_use_admonition_for_examples = False napoleon_use_admonition_for_notes = False napoleon_use_admonition_for_references = False napoleon_use_ivar = False napoleon_use_param = True napoleon_use_rtype = True crccheck-1.3.0/docs/source/crccheck.rst000066400000000000000000000011301432207626700200130ustar00rootroot00000000000000crccheck package ================ Submodules ---------- crccheck.base module -------------------- .. automodule:: crccheck.base :members: :undoc-members: :show-inheritance: crccheck.checksum module ------------------------ .. automodule:: crccheck.checksum :members: :undoc-members: :show-inheritance: crccheck.crc module ------------------- .. automodule:: crccheck.crc :members: :undoc-members: :show-inheritance: Module contents --------------- .. automodule:: crccheck :members: :undoc-members: :show-inheritance: crccheck-1.3.0/docs/source/crctable.rst000066400000000000000000001764051432207626700200470ustar00rootroot00000000000000Supported CRCs ============== +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC Name | Class | Bit width | Poly | Initvalue | Reflect input | Reflect output | XOR output | Check | Residue | +==========================+====================+===========+==========================+======================+===============+================+======================+==========================+======================+ | CRC-3/GSM | Crc3Gsm | 3 | 0x3 | 0x0 | False | False | 0x7 | 0x4 | 0x2 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-3/ROHC | Crc3Rohc | 3 | 0x3 | 0x7 | True | True | 0x0 | 0x6 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-4/G-704 | Crc4G704 | 4 | 0x3 | 0x0 | True | True | 0x0 | 0x7 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-4/INTERLAKEN | Crc4Interlaken | 4 | 0x3 | 0xF | False | False | 0xF | 0xB | 0x2 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-5/EPC-C1G2 | Crc5EpcC1G2 | 5 | 0x9 | 0x9 | False | False | 0x0 | 0x0 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-5/G-704 | Crc5G704 | 5 | 0x15 | 0x0 | True | True | 0x0 | 0x7 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-5/USB | Crc5Usb | 5 | 0x5 | 0x1F | True | True | 0x1F | 0x19 | 0x6 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-6/CDMA2000-A | Crc6Cdma2000A | 6 | 0x27 | 0x3F | False | False | 0x0 | 0xD | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-6/CDMA2000-B | Crc6Cdma2000B | 6 | 0x7 | 0x3F | False | False | 0x0 | 0x3B | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-6/DARC | Crc6Darc | 6 | 0x19 | 0x0 | True | True | 0x0 | 0x26 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-6/G-704 | Crc6G704 | 6 | 0x3 | 0x0 | True | True | 0x0 | 0x6 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-6/GSM | Crc6Gsm | 6 | 0x2F | 0x0 | False | False | 0x3F | 0x13 | 0x3A | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-7/MMC | Crc7Mmc | 7 | 0x9 | 0x0 | False | False | 0x0 | 0x75 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-7/ROHC | Crc7Rohc | 7 | 0x4F | 0x7F | True | True | 0x0 | 0x53 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-7/UMTS | Crc7Umts | 7 | 0x45 | 0x0 | False | False | 0x0 | 0x61 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/AUTOSAR | Crc8Autosar | 8 | 0x2F | 0xFF | False | False | 0xFF | 0xDF | 0x42 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/BLUETOOTH | Crc8Bluetooth | 8 | 0xA7 | 0x0 | True | True | 0x0 | 0x26 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/CDMA2000 | Crc8Cdma2000 | 8 | 0x9B | 0xFF | False | False | 0x0 | 0xDA | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/DARC | Crc8Darc | 8 | 0x39 | 0x0 | True | True | 0x0 | 0x15 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/DVB-S2 | Crc8DvbS2 | 8 | 0xD5 | 0x0 | False | False | 0x0 | 0xBC | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/GSM-A | Crc8GsmA | 8 | 0x1D | 0x0 | False | False | 0x0 | 0x37 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/GSM-B | Crc8GsmB | 8 | 0x49 | 0x0 | False | False | 0xFF | 0x94 | 0x53 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/HITAG | Crc8Hitag | 8 | 0x1D | 0xFF | False | False | 0x0 | 0xB4 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/I-432-1 | Crc8I4321 | 8 | 0x7 | 0x0 | False | False | 0x55 | 0xA1 | 0xAC | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/I-CODE | Crc8ICode | 8 | 0x1D | 0xFD | False | False | 0x0 | 0x7E | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/LTE | Crc8Lte | 8 | 0x9B | 0x0 | False | False | 0x0 | 0xEA | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/MAXIM-DOW | Crc8MaximDow | 8 | 0x31 | 0x0 | True | True | 0x0 | 0xA1 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/MIFARE-MAD | Crc8MifareMad | 8 | 0x1D | 0xC7 | False | False | 0x0 | 0x99 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/NRSC-5 | Crc8Nrsc5 | 8 | 0x31 | 0xFF | False | False | 0x0 | 0xF7 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/OPENSAFETY | Crc8Opensafety | 8 | 0x2F | 0x0 | False | False | 0x0 | 0x3E | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/ROHC | Crc8Rohc | 8 | 0x7 | 0xFF | True | True | 0x0 | 0xD0 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/SAE-J1850 | Crc8SaeJ1850 | 8 | 0x1D | 0xFF | False | False | 0xFF | 0x4B | 0xC4 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/SMBUS | Crc8Smbus | 8 | 0x7 | 0x0 | False | False | 0x0 | 0xF4 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/TECH-3250 | Crc8Tech3250 | 8 | 0x1D | 0xFF | True | True | 0x0 | 0x97 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-8/WCDMA | Crc8Wcdma | 8 | 0x9B | 0x0 | True | True | 0x0 | 0x25 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-10/ATM | Crc10Atm | 10 | 0x233 | 0x0 | False | False | 0x0 | 0x199 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-10/CDMA2000 | Crc10Cdma2000 | 10 | 0x3D9 | 0x3FF | False | False | 0x0 | 0x233 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-10/GSM | Crc10Gsm | 10 | 0x175 | 0x0 | False | False | 0x3FF | 0x12A | 0xC6 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-11/FLEXRAY | Crc11Flexray | 11 | 0x385 | 0x1A | False | False | 0x0 | 0x5A3 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-11/UMTS | Crc11Umts | 11 | 0x307 | 0x0 | False | False | 0x0 | 0x61 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-12/CDMA2000 | Crc12Cdma2000 | 12 | 0xF13 | 0xFFF | False | False | 0x0 | 0xD4D | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-12/DECT | Crc12Dect | 12 | 0x80F | 0x0 | False | False | 0x0 | 0xF5B | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-12/GSM | Crc12Gsm | 12 | 0xD31 | 0x0 | False | False | 0xFFF | 0xB34 | 0x178 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-12/UMTS | Crc12Umts | 12 | 0x80F | 0x0 | False | True | 0x0 | 0xDAF | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-13/BBC | Crc13Bbc | 13 | 0x1CF5 | 0x0 | False | False | 0x0 | 0x4FA | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-14/DARC | Crc14Darc | 14 | 0x805 | 0x0 | True | True | 0x0 | 0x82D | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-14/GSM | Crc14Gsm | 14 | 0x202D | 0x0 | False | False | 0x3FFF | 0x30AE | 0x31E | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-15/CAN | Crc15Can | 15 | 0x4599 | 0x0 | False | False | 0x0 | 0x59E | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-15/MPT1327 | Crc15Mpt1327 | 15 | 0x6815 | 0x0 | False | False | 0x1 | 0x2566 | 0x6815 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/ARC | Crc16Arc | 16 | 0x8005 | 0x0 | True | True | 0x0 | 0xBB3D | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/CDMA2000 | Crc16Cdma2000 | 16 | 0xC867 | 0xFFFF | False | False | 0x0 | 0x4C06 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/CMS | Crc16Cms | 16 | 0x8005 | 0xFFFF | False | False | 0x0 | 0xAEE7 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/DDS-110 | Crc16Dds110 | 16 | 0x8005 | 0x800D | False | False | 0x0 | 0x9ECF | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/DECT-R | Crc16DectR | 16 | 0x589 | 0x0 | False | False | 0x1 | 0x7E | 0x589 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/DECT-X | Crc16DectX | 16 | 0x589 | 0x0 | False | False | 0x0 | 0x7F | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/DNP | Crc16Dnp | 16 | 0x3D65 | 0x0 | True | True | 0xFFFF | 0xEA82 | 0x66C5 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/EN-13757 | Crc16En13757 | 16 | 0x3D65 | 0x0 | False | False | 0xFFFF | 0xC2B7 | 0xA366 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/GENIBUS | Crc16Genibus | 16 | 0x1021 | 0xFFFF | False | False | 0xFFFF | 0xD64E | 0x1D0F | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/GSM | Crc16Gsm | 16 | 0x1021 | 0x0 | False | False | 0xFFFF | 0xCE3C | 0x1D0F | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/IBM-3740 | Crc16Ibm3740 | 16 | 0x1021 | 0xFFFF | False | False | 0x0 | 0x29B1 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/IBM-SDLC | Crc16IbmSdlc | 16 | 0x1021 | 0xFFFF | True | True | 0xFFFF | 0x906E | 0xF0B8 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/ISO-IEC-14443-3-A | Crc16IsoIec144433A | 16 | 0x1021 | 0xC6C6 | True | True | 0x0 | 0xBF05 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/KERMIT | Crc16Kermit | 16 | 0x1021 | 0x0 | True | True | 0x0 | 0x2189 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/LJ1200 | Crc16Lj1200 | 16 | 0x6F63 | 0x0 | False | False | 0x0 | 0xBDF4 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/M17 | Crc16M17 | 16 | 0x5935 | 0xFFFF | False | False | 0x0 | 0x772B | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/MAXIM-DOW | Crc16MaximDow | 16 | 0x8005 | 0x0 | True | True | 0xFFFF | 0x44C2 | 0xB001 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/MCRF4XX | Crc16Mcrf4Xx | 16 | 0x1021 | 0xFFFF | True | True | 0x0 | 0x6F91 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/MODBUS | Crc16Modbus | 16 | 0x8005 | 0xFFFF | True | True | 0x0 | 0x4B37 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/NRSC-5 | Crc16Nrsc5 | 16 | 0x80B | 0xFFFF | True | True | 0x0 | 0xA066 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/OPENSAFETY-A | Crc16OpensafetyA | 16 | 0x5935 | 0x0 | False | False | 0x0 | 0x5D38 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/OPENSAFETY-B | Crc16OpensafetyB | 16 | 0x755B | 0x0 | False | False | 0x0 | 0x20FE | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/PROFIBUS | Crc16Profibus | 16 | 0x1DCF | 0xFFFF | False | False | 0xFFFF | 0xA819 | 0xE394 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/RIELLO | Crc16Riello | 16 | 0x1021 | 0xB2AA | True | True | 0x0 | 0x63D0 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/SPI-FUJITSU | Crc16SpiFujitsu | 16 | 0x1021 | 0x1D0F | False | False | 0x0 | 0xE5CC | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/T10-DIF | Crc16T10Dif | 16 | 0x8BB7 | 0x0 | False | False | 0x0 | 0xD0DB | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/TELEDISK | Crc16Teledisk | 16 | 0xA097 | 0x0 | False | False | 0x0 | 0xFB3 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/TMS37157 | Crc16Tms37157 | 16 | 0x1021 | 0x89EC | True | True | 0x0 | 0x26B1 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/UMTS | Crc16Umts | 16 | 0x8005 | 0x0 | False | False | 0x0 | 0xFEE8 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/USB | Crc16Usb | 16 | 0x8005 | 0xFFFF | True | True | 0xFFFF | 0xB4C8 | 0xB001 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-16/XMODEM | Crc16Xmodem | 16 | 0x1021 | 0x0 | False | False | 0x0 | 0x31C3 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-17/CAN-FD | Crc17CanFd | 17 | 0x1685B | 0x0 | False | False | 0x0 | 0x4F03 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-21/CAN-FD | Crc21CanFd | 21 | 0x102899 | 0x0 | False | False | 0x0 | 0xED841 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/BLE | Crc24Ble | 24 | 0x65B | 0x555555 | True | True | 0x0 | 0xC25A56 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/FLEXRAY-A | Crc24FlexrayA | 24 | 0x5D6DCB | 0xFEDCBA | False | False | 0x0 | 0x7979BD | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/FLEXRAY-B | Crc24FlexrayB | 24 | 0x5D6DCB | 0xABCDEF | False | False | 0x0 | 0x1F23B8 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/INTERLAKEN | Crc24Interlaken | 24 | 0x328B63 | 0xFFFFFF | False | False | 0xFFFFFF | 0xB4F3E6 | 0x144E63 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/LTE-A | Crc24LteA | 24 | 0x864CFB | 0x0 | False | False | 0x0 | 0xCDE703 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/LTE-B | Crc24LteB | 24 | 0x800063 | 0x0 | False | False | 0x0 | 0x23EF52 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/OPENPGP | Crc24Openpgp | 24 | 0x864CFB | 0xB704CE | False | False | 0x0 | 0x21CF02 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-24/OS-9 | Crc24Os9 | 24 | 0x800063 | 0xFFFFFF | False | False | 0xFFFFFF | 0x200FA5 | 0x800FE3 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-30/CDMA | Crc30Cdma | 30 | 0x2030B9C7 | 0x3FFFFFFF | False | False | 0x3FFFFFFF | 0x4C34ABF | 0x34EFA55A | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-31/PHILIPS | Crc31Philips | 31 | 0x4C11DB7 | 0x7FFFFFFF | False | False | 0x7FFFFFFF | 0xCE9E46C | 0x4EAF26F1 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/AIXM | Crc32Aixm | 32 | 0x814141AB | 0x0 | False | False | 0x0 | 0x3010BF7F | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/AUTOSAR | Crc32Autosar | 32 | 0xF4ACFB13 | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0x1697D06A | 0x904CDDBF | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/BASE91-D | Crc32Base91D | 32 | 0xA833982B | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0x87315576 | 0x45270551 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/BZIP2 | Crc32Bzip2 | 32 | 0x4C11DB7 | 0xFFFFFFFF | False | False | 0xFFFFFFFF | 0xFC891918 | 0xC704DD7B | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/CD-ROM-EDC | Crc32CdRomEdc | 32 | 0x8001801B | 0x0 | True | True | 0x0 | 0x6EC2EDC4 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/CKSUM | Crc32Cksum | 32 | 0x4C11DB7 | 0x0 | False | False | 0xFFFFFFFF | 0x765E7680 | 0xC704DD7B | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/ISCSI | Crc32Iscsi | 32 | 0x1EDC6F41 | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0xE3069283 | 0xB798B438 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/ISO-HDLC | Crc32IsoHdlc | 32 | 0x4C11DB7 | 0xFFFFFFFF | True | True | 0xFFFFFFFF | 0xCBF43926 | 0xDEBB20E3 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/JAMCRC | Crc32Jamcrc | 32 | 0x4C11DB7 | 0xFFFFFFFF | True | True | 0x0 | 0x340BC6D9 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/MEF | Crc32Mef | 32 | 0x741B8CD7 | 0xFFFFFFFF | True | True | 0x0 | 0xD2C22F51 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/MPEG-2 | Crc32Mpeg2 | 32 | 0x4C11DB7 | 0xFFFFFFFF | False | False | 0x0 | 0x376E6E7 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-32/XFER | Crc32Xfer | 32 | 0xAF | 0x0 | False | False | 0x0 | 0xBD0BE338 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-40/GSM | Crc40Gsm | 40 | 0x4820009 | 0x0 | False | False | 0xFFFFFFFFFF | 0xD4164FC646 | 0xC4FF8071FF | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-64/ECMA-182 | Crc64Ecma182 | 64 | 0x42F0E1EBA9EA3693 | 0x0 | False | False | 0x0 | 0x6C40DF5F0B497347 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-64/GO-ISO | Crc64GoIso | 64 | 0x1B | 0xFFFFFFFFFFFFFFFF | True | True | 0xFFFFFFFFFFFFFFFF | 0xB90956C775A41001 | 0x5300000000000000 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-64/MS | Crc64Ms | 64 | 0x259C84CBA6426349 | 0xFFFFFFFFFFFFFFFF | True | True | 0x0 | 0x75D4B74F024ECEEA | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-64/REDIS | Crc64Redis | 64 | 0xAD93D23594C935A9 | 0x0 | True | True | 0x0 | 0xE9C6D914C4B8D9CA | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-64/WE | Crc64We | 64 | 0x42F0E1EBA9EA3693 | 0xFFFFFFFFFFFFFFFF | False | False | 0xFFFFFFFFFFFFFFFF | 0x62EC59E3F1A4F00A | 0xFCACBEBD5931A992 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-64/XZ | Crc64Xz | 64 | 0x42F0E1EBA9EA3693 | 0xFFFFFFFFFFFFFFFF | True | True | 0xFFFFFFFFFFFFFFFF | 0x995DC9BBDF1939FA | 0x49958C9ABD7D353F | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ | CRC-82/DARC | Crc82Darc | 82 | 0x308C0111011401440411 | 0x0 | True | True | 0x0 | 0x9EA83F625023801FD612 | 0x0 | +--------------------------+--------------------+-----------+--------------------------+----------------------+---------------+----------------+----------------------+--------------------------+----------------------+ Aliases ------- As some CRCs are also known under different names aliases for the CRC classes are defined. +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC | Class | Alias | Alias Classes | +==========================+====================+=====================================================================+==============================================================+ | CRC-4/G-704 | Crc4G704 | CRC-4/ITU | Crc4Itu | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-5/EPC-C1G2 | Crc5EpcC1G2 | CRC-5/EPC | Crc5Epc | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-5/G-704 | Crc5G704 | CRC-5/ITU | Crc5Itu | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-6/G-704 | Crc6G704 | CRC-6/ITU | Crc6Itu | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-7/MMC | Crc7Mmc | CRC-7 | Crc7 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-8/I-432-1 | Crc8I4321 | CRC-8/ITU | Crc8Itu | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-8/MAXIM-DOW | Crc8MaximDow | CRC-8/MAXIM, DOW-CRC | Crc8Maxim, CrcDow | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-8/SMBUS | Crc8Smbus | CRC-8 | Crc8 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-8/TECH-3250 | Crc8Tech3250 | CRC-8/AES, CRC-8/EBU | Crc8Aes, Crc8Ebu | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-10/ATM | Crc10Atm | CRC-10, CRC-10/I-610 | Crc10, Crc10I610 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-11/FLEXRAY | Crc11Flexray | CRC-11 | Crc11 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-12/DECT | Crc12Dect | CRC-12-X | Crc12X | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-12/UMTS | Crc12Umts | CRC-12/3GPP | Crc123Gpp | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-15/CAN | Crc15Can | CRC-15 | Crc15 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/ARC | Crc16Arc | ARC, CRC-16/LHA, CRC-IBM | CrcArc, Crc16Lha, CrcIbm | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/DECT-R | Crc16DectR | R-CRC-16 | Crc16R | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/DECT-X | Crc16DectX | X-CRC-16 | Crc16X | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/GENIBUS | Crc16Genibus | CRC-16/DARC, CRC-16/EPC, CRC-16/EPC-C1G2, CRC-16/I-CODE | Crc16Darc, Crc16Epc, Crc16EpcC1G2, Crc16ICode | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/IBM-3740 | Crc16Ibm3740 | CRC-16/AUTOSAR, CRC-16/CCITT-FALSE | Crc16Autosar, Crc16CcittFalse | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | 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 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/ISO-IEC-14443-3-A | Crc16IsoIec144433A | CRC-A | CrcA | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/KERMIT | Crc16Kermit | CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/V-41-LSB, CRC-CCITT, KERMIT | Crc16Ccitt, Crc16CcittTrue, Crc16V41Lsb, CrcCcitt, CrcKermit | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/MAXIM-DOW | Crc16MaximDow | CRC-16/MAXIM | Crc16Maxim | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/MODBUS | Crc16Modbus | MODBUS | CrcModbus | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/PROFIBUS | Crc16Profibus | CRC-16/IEC-61158-2 | Crc16Iec611582 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/SPI-FUJITSU | Crc16SpiFujitsu | CRC-16/AUG-CCITT | Crc16AugCcitt | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/UMTS | Crc16Umts | CRC-16/BUYPASS, CRC-16/VERIFONE | Crc16Buypass, Crc16Verifone | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-16/XMODEM | Crc16Xmodem | CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM | Crc16Acorn, Crc16Lte, Crc16V41Msb, CrcXmodem, CrcZmodem | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-24/OPENPGP | Crc24Openpgp | CRC-24 | Crc24 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/AIXM | Crc32Aixm | CRC-32Q | Crc32Q | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/BASE91-D | Crc32Base91D | CRC-32D | Crc32D | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/BZIP2 | Crc32Bzip2 | CRC-32/AAL5, CRC-32/DECT-B, B-CRC-32 | Crc32Aal5, Crc32DectB, Crc32B | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/CKSUM | Crc32Cksum | CKSUM, CRC-32/POSIX | CrcCksum, Crc32Posix | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/ISCSI | Crc32Iscsi | CRC-32/BASE91-C, CRC-32/CASTAGNOLI, CRC-32/INTERLAKEN, CRC-32C | Crc32Base91C, Crc32Castagnoli, Crc32Interlaken, Crc32C | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/ISO-HDLC | Crc32IsoHdlc | CRC-32, CRC-32/ADCCP, CRC-32/V-42, CRC-32/XZ, PKZIP | Crc32, Crc32Adccp, Crc32V42, Crc32Xz, CrcPkzip | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/JAMCRC | Crc32Jamcrc | JAMCRC | CrcJamcrc | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-32/XFER | Crc32Xfer | XFER | CrcXfer | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-64/ECMA-182 | Crc64Ecma182 | CRC-64 | Crc64 | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ | CRC-64/XZ | Crc64Xz | CRC-64/GO-ECMA | Crc64GoEcma | +--------------------------+--------------------+---------------------------------------------------------------------+--------------------------------------------------------------+ crccheck-1.3.0/docs/source/howto.rst000066400000000000000000000037041432207626700174170ustar00rootroot00000000000000====== How-to ====== How to quickly calculate a CRC/checksum ======================================= If only one data buffer needs to be processed a CRC/checksum can be generated quickly using the class method :meth:`.calc`:: from crccheck.crc import Crc32 crc = Crc32.calc(data) If the result is needed as hexstring or bytes use :meth:`.calchex` or :meth:`.calcbytes`, respectively. How to calculate over multiple data blocks ========================================== Create an instance and feed all data blocks to :meth:`.process`. Once done, use :meth:`.final` to get the final result:: from crccheck.crc import Crc32 crcinst = Crc32() crcinst.process(data1) crcinst.process(data2) crcinst.process(data3) crc = crcinst.final() The intermediate value can be read using :meth:`.value` and, if required, set again using :meth:`.init`. How to use a CRC not implemented by the package =============================================== The package implements all CRCs listed in the `Catalogue of parametrised CRC algorithms `_. The general class :class:`crccheck.crc.Crc` can be used for any other CRCs. You need to provide the CRC parameters. These are described in detail in the publication `A paninless guide to CRC error detection alogithms `_. For advanced users is also possible to create an own subclass. See the source code for details. How to calculate the CRC or checksum of a file ============================================== You need to provide an interable over all bytes in the file. For this `mmap `_ is recommended:: from mmap import ACCESS_READ, mmap from crccheck.crc import Crc32 with open("somefile.ext", 'rb') as fh, mmap(fh.fileno(), 0, access=ACCESS_READ) as mm: crc = Crc32.calc((b[0] for b in mm)) crccheck-1.3.0/docs/source/index.rst000066400000000000000000000004011432207626700173550ustar00rootroot00000000000000======== crccheck ======== .. automodule:: crccheck Contents: .. toctree:: :maxdepth: 2 crccheck crctable howto changelog Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` crccheck-1.3.0/docs/source/modules.rst000066400000000000000000000000751432207626700177250ustar00rootroot00000000000000crccheck ======== .. toctree:: :maxdepth: 4 crccheck crccheck-1.3.0/setup.py000066400000000000000000000053131432207626700150050ustar00rootroot00000000000000#!/usr/bin/python """ Setup file for crccheck package. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import os try: from setuptools import setup except ImportError: from distutils.core import setup def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name='crccheck', description='Calculation library for CRCs and checksums', long_description_content_type='text/x-rst', long_description=read("README.rst"), author='Martin Scharrer', author_email='martin.scharrer@web.de', license='MIT', license_files=['LICENSE.txt'], packages=['crccheck'], test_suite='tests', version='1.3.0', url='https://github.com/MartinScharrer/crccheck', install_requires=[], classifiers=[ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Topic :: Scientific/Engineering", "Topic :: Software Development :: Embedded Systems", "Topic :: Utilities", ], ) crccheck-1.3.0/tests/000077500000000000000000000000001432207626700144335ustar00rootroot00000000000000crccheck-1.3.0/tests/__init__.py000066400000000000000000000026461432207626700165540ustar00rootroot00000000000000"""Test modules for crccheck package. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import random from unittest import TestCase try: from random import randbytes except ImportError: def randbytes(length): return [random.randint(0, 255) for _ in range(0, length)] crccheck-1.3.0/tests/test_base.py000066400000000000000000000140471432207626700167640ustar00rootroot00000000000000"""Test modules for base package. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import random import sys from crccheck.base import CrccheckBase from crccheck.crc import ALLCRCCLASSES from tests import TestCase, randbytes class TestBase(TestCase): def test_abstract_method(self): """ For coverage """ with self.assertRaises(NotImplementedError): ab = CrccheckBase() ab.process(bytearray(10)) def test_init(self): for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): value = random.randint(0, 4294967295) self.assertEqual(CrcClass(value).value(), value) def test_reset(self): for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): value = random.randint(0, 4294967295) c = CrcClass() c.reset(value) self.assertEqual(c.value(), value) def test_final(self): """.final() should not change internal value""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(crc.final(), crc.final()) def test_finalhex(self): """.finalhex() should match .final()""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(crc.final(), int(crc.finalhex(), 16)) def test_finalbytes_big(self): """.finalbytes() should match .final()""" if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(crc.final(), int.from_bytes(crc.finalbytes('big'), 'big')) def test_finalbytes_little(self): """.finalbytes() should match .final()""" if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(crc.final(), int.from_bytes(crc.finalbytes('little'), 'little')) def test_calc(self): """.calc() must be identical to .process() + .final()""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(CrcClass.calc(data), crc.final()) def test_calchex_big(self): """.calchex() must be identical to .process() + .finalhex()""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(CrcClass.calchex(data, byteorder='big'), crc.finalhex('big')) def test_calchex_little(self): """.calchex() must be identical to .process() + .finalhex()""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertEqual(CrcClass.calchex(data, byteorder='little'), crc.finalhex('little')) def test_calcbytes_big(self): """.calcbytes() must be identical to .process() + .finalbytes()""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertSequenceEqual(CrcClass.calcbytes(data, byteorder='big'), crc.finalbytes('big')) def test_calcbytes_little(self): """.calcbytes() must be identical to .process() + .finalbytes()""" for CrcClass in ALLCRCCLASSES: with self.subTest(CrcClass): for n in range(0, 16): data = randbytes(16) crc = CrcClass() crc.process(data) self.assertSequenceEqual(CrcClass.calcbytes(data, byteorder='little'), crc.finalbytes('little')) crccheck-1.3.0/tests/test_checksum.py000066400000000000000000000107561432207626700176570ustar00rootroot00000000000000""" Unit tests for checksum module. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import sys from crccheck import checksum from crccheck.base import CrccheckError from crccheck.checksum import ALLCHECKSUMCLASSES, Checksum32, Checksum, ChecksumXor from tests import TestCase, randbytes class TestChecksum(TestCase): def test_allchecksums_bigendian(self): for checksumclass in ALLCHECKSUMCLASSES: with self.subTest(checksumclass=checksumclass): checksumclass.selftest(byteorder='big') def test_allchecksums_littleendian(self): for checksumclass in ALLCHECKSUMCLASSES: with self.subTest(checksumclass=checksumclass): checksumclass.selftest(byteorder='little') # noinspection PyProtectedMember def test_allchecksums_fail(self): with self.assertRaises(CrccheckError): checksumclass = ALLCHECKSUMCLASSES[0] checksumclass.selftest(checksumclass._check_data, ~checksumclass._check_result) def test_generator(self): Checksum32.calc((n for n in range(0, 255))) def test_list1(self): Checksum32.calc([n for n in range(0, 255)]) def test_list2(self): Checksum32.calc([n for n in range(0, 255)], 1) def test_bytearray1(self): Checksum32.calc(bytearray.fromhex("12345678909876543210")) def test_bytes(self): if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") Checksum32.calc(bytes.fromhex("12345678909876543210")) def test_string1(self): if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") Checksum32.calc(b"Teststring") def test_string3(self): if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") Checksum32.calc("Teststring".encode(), ) def test_general_checksum_valid_width(self): """ Checksum() Should allow for any positive width which is a multiple of 8. """ for n in range(8, 129, 8): Checksum(n) def test_general_checksum_invalid_width(self): for n in (0, 1, 7, 9, 33): with self.assertRaises(ValueError): Checksum(n) def test_general_checksum_ident(self): data = randbytes(1024) self.assertEqual(checksum.Checksum32.calc(data), checksum.Checksum(32).process(data).final()) self.assertEqual(checksum.Checksum16.calc(data), checksum.Checksum(16).process(data).final()) self.assertEqual(checksum.Checksum8.calc(data), checksum.Checksum(8).process(data).final()) def test_general_checksumxor_valid_width(self): """ Checksum() Should allow for any positive width which is a multiple of 8. """ for n in range(8, 129, 8): ChecksumXor(n) def test_general_checksumxor_invalid_width(self): for n in (0, 1, 7, 9, 33): with self.assertRaises(ValueError): ChecksumXor(n) def test_general_checksumxor_ident(self): data = randbytes(1024) self.assertEqual(checksum.ChecksumXor32.calc(data), checksum.ChecksumXor(32).process(data).final()) self.assertEqual(checksum.ChecksumXor16.calc(data), checksum.ChecksumXor(16).process(data).final()) self.assertEqual(checksum.ChecksumXor8.calc(data), checksum.ChecksumXor(8).process(data).final()) crccheck-1.3.0/tests/test_crc.py000066400000000000000000000214511432207626700166160ustar00rootroot00000000000000""" Unit tests for checksum module. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import random import sys import crccheck from crccheck.base import CrccheckError from crccheck.crc import ALLCRCCLASSES, ALLCRCCLASSES_ALIASES, \ Crc32, Crc, find, identify, \ Crc8Base, Crc16Base, Crc32Base from tests import TestCase TESTCRCCLASSES = list(ALLCRCCLASSES) + [Crc8Base, Crc16Base, Crc32Base] class TestCrc(TestCase): def test_allcrc(self): """Test if expected 'check' result is calulated with standard test vector.""" for crcclass in TESTCRCCLASSES: with self.subTest(crcclass=crcclass): crcclass.selftest() def test_allcrcfail(self): """Test if 'check' result is not reached with different input.""" for crcclass in TESTCRCCLASSES: with self.subTest(crcclass=crcclass), self.assertRaises(CrccheckError): crcclass.selftest(bytearray(b"wrongtestinput"), crcclass._check_result) def test_generator(self): Crc32.calc((n for n in range(0, 255))) def test_list1(self): Crc32.calc([n for n in range(0, 255)]) def test_list2(self): Crc32.calc([n for n in range(0, 255)], 123) def test_bytearray(self): Crc32.calc(bytearray.fromhex("12345678909876543210")) def test_bytes(self): if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") Crc32.calc(bytes.fromhex("12345678909876543210")) def test_string1(self): if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") Crc32.calc(b"Teststring") def test_string2(self): if sys.version_info < (3, 3, 0): # pragma: no cover raise self.skipTest("") Crc32.calc("Teststring".encode(), ) def test_general_crc(self): crc = Crc(32, 0x4C11DB7, 0xFFFFFFFF, True, True, 0x00000000, 0x340BC6D9) crc.selftest() def test_general_crc_fail(self): with self.assertRaises(CrccheckError): crc = Crc(32, 0x4C11DB7, 0xFFFFFFFF, True, True, 0x00000000, ~0x340BC6D9) crc.selftest() def test_backwards_compatible(self): """Crc8Base was called Crc8, etc. Must still be equal CRCs""" self.assertEqual(crccheck.crc.Crc8(), crccheck.crc.Crc8Base()) self.assertEqual(crccheck.crc.Crc16(), crccheck.crc.Crc16Base()) self.assertEqual(crccheck.crc.Crc32(), crccheck.crc.Crc32Base()) def test_find32(self): for cls in find(width=32): self.assertEqual(cls._width, 32) def test_find_unknown(self): self.assertEqual(len(find(width=12345)), 0) def test_find_all(self): self.assertEqual(find(), list(ALLCRCCLASSES)) def test_find_some(self): self.assertListEqual(find(ALLCRCCLASSES[1:3]), list(ALLCRCCLASSES[1:3])) def test_find_width(self): self.assertListEqual(find(width=32), list(cls for cls in ALLCRCCLASSES if cls._width == 32)) def test_find_poly(self): self.assertListEqual(find(poly=0x04C11DB7), list(cls for cls in ALLCRCCLASSES if cls._poly == 0x04C11DB7)) def test_find_initvalue(self): self.assertListEqual(find(initvalue=0), list(cls for cls in ALLCRCCLASSES if cls._initvalue == 0)) def test_find_reflect_input(self): self.assertListEqual(find(reflect_input=True), list(cls for cls in ALLCRCCLASSES if cls._reflect_input)) def test_find_reflect_output(self): self.assertListEqual(find(reflect_output=False), list(cls for cls in ALLCRCCLASSES if not cls._reflect_output)) def test_find_xor_output(self): self.assertListEqual(find(xor_output=0), list(cls for cls in ALLCRCCLASSES if cls._xor_output == 0)) def test_find_check_result(self): self.assertListEqual(find(check_result=6), list(cls for cls in ALLCRCCLASSES if cls._check_result == 6)) def test_find_residue(self): self.assertListEqual(find(residue=0), list(cls for cls in ALLCRCCLASSES if cls._residue == 0)) def test_find_mixed(self): self.assertListEqual( find(ALLCRCCLASSES[0:20], width=8, residue=0, reflect_input=False, reflect_output=False), list(cls for cls in ALLCRCCLASSES[0:20] if cls._width == 8 and cls._residue == 0 and not cls._reflect_input and not cls._reflect_output)) def test_identify_1(self): data = bytes(random.randrange(256) for _ in range(10)) cls = crccheck.crc.Crc64GoIso self.assertEqual(identify(data, cls.calc(data))(), cls()) def test_identify_2(self): data = bytes(random.randrange(256) for _ in range(10)) classes = [crccheck.crc.Crc64GoIso, crccheck.crc.Crc8, crccheck.crc.Crc32IsoHdlc] cls = crccheck.crc.Crc32IsoHdlc self.assertEqual(identify(data, cls.calc(data), classes=classes)(), cls()) def test_identify_width(self): data = bytes(random.randrange(256) for _ in range(10)) allcrc32 = [c for c in ALLCRCCLASSES if c._width == 32] cls = random.choice(allcrc32) self.assertEqual(identify(data, cls.calc(data), 32)(), cls()) self.assertEqual(identify(data, cls.calc(data), 32, allcrc32)(), cls()) def test_identify_width_list(self): data = bytes(random.randrange(256) for _ in range(10)) allcrc32 = [c for c in ALLCRCCLASSES if c._width == 32] cls = random.choice(allcrc32) result = identify(data, cls.calc(data), 32, one=False) self.assertEqual(len(result) >= 1 and result[0](), cls()) result = identify(data, cls.calc(data), 32, allcrc32, one=False) self.assertEqual(len(result) >= 1 and result[0](), cls()) def test_identify_notexisting(self): self.assertIsNone(identify(b'Test', 0)) self.assertIsNone(identify(b'Test', 0, 234)) self.assertIsNone(identify(b'Test', 0, classes=[])) self.assertIsNone(identify(b'Test', 0, 235, classes=[])) self.assertListEqual(identify(b'Test', 0, one=False), []) self.assertListEqual(identify(b'Test', 0, 234, one=False), []) self.assertListEqual(identify(b'Test', 0, classes=[], one=False), []) self.assertListEqual(identify(b'Test', 0, 235, classes=[], one=False), []) def test_repr(self): """Test if __repr__ does not cause errors""" c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False, xor_output=0x00, check_result=None, residue=None) # noinspection PyUnusedLocal r = repr(c) c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False, xor_output=0x00, check_result=None, residue=0x00) # noinspection PyUnusedLocal r = repr(c) c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False, xor_output=0x00, check_result=0x00, residue=None) # noinspection PyUnusedLocal r = repr(c) c = Crc(16, 0xDEAD, initvalue=0x00, reflect_input=False, reflect_output=False, xor_output=0x00, check_result=0x00, residue=0x00) # noinspection PyUnusedLocal r = repr(c) def test_selftest_data(self): c = Crc(21, 0xDEAD) c.selftest(b'Test', 0x40be8) def test_crc_calc(self): self.assertEqual(Crc(21, 0xDEAD).calc(b'Test'), 265192) def test_crc_calchex(self): self.assertEqual(Crc(21, 0xDEAD).calchex(b'Test'), '040be8') def test_crc_calcbytes_big(self): self.assertEqual(Crc(21, 0xDEAD).calcbytes(b'Test', byteorder='big'), b'\x04\x0b\xe8') def test_crc_calcbytes_little(self): self.assertEqual(Crc(21, 0xDEAD).calcbytes(b'Test', byteorder='little'), b'\xe8\x0b\x04') def test_aliases(self): self.assertTrue(set(ALLCRCCLASSES).issubset(ALLCRCCLASSES_ALIASES)) crccheck-1.3.0/tests/test_reflectbitorder.py000066400000000000000000000050331432207626700212240ustar00rootroot00000000000000""" Unit tests for reflectbitorder function. License:: MIT License Copyright (c) 2015-2022 by Martin Scharrer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from crccheck.base import reflectbitorder from tests import TestCase class TestReflectBitOrder(TestCase): def test_1(self): self.assertEqual(reflectbitorder(8, 0x80), 0x01) def test_2(self): self.assertEqual(reflectbitorder(16, 0x8000), 0x0001) def test_3(self): self.assertEqual(reflectbitorder(8, 0x81), 0x81) def test_4(self): self.assertEqual(reflectbitorder(80, (1 << 79)), 0x01) def test_5(self): self.assertEqual(reflectbitorder(65, 0x1), (1 << 64)) def test_6(self): self.assertEqual(reflectbitorder(3, 0b110), 0b011) def test_7(self): self.assertEqual(reflectbitorder(3, 0b110), 0b011) def test_8(self): self.assertEqual(reflectbitorder(0, 0), 0) def expect(self, w, v, e): self.assertEqual(reflectbitorder(w, v), e) def test_random(self): import random random.seed() for width in range(1, 125): # noinspection PyUnusedLocal randombitstr = "".join([str(random.randint(0, 1)) for m in range(0, width)]) value = int(randombitstr, 2) expectedresult = int("".join(reversed(randombitstr)), 2) with self.subTest(width=width): self.expect(width, value, expectedresult)