crccheck package¶
Submodules¶
crccheck.base module¶
Base class for CRC and checksum classes.
License:
MIT License
Copyright (c) 2015-2022 by Martin Scharrer <martin.scharrer@web.de>
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.base.reflectbitorder(width, value)[source]¶
Reflects the bit order of the given value according to the given bit width.
- class crccheck.base.CrccheckBase(initvalue=None)[source]¶
Bases:
object
Abstract base class for checksumming classes.
- Parameters
initvalue (int) – Initial value. If None then the default value for the class is used.
- reset(value=None)[source]¶
Reset instance.
Resets the instance state to the initial value. This is not required for a just created instance.
- Parameters
value (int) – Set internal value. If None then the default initial value for the class is used.
- Returns
self
- final()[source]¶
Return final check value. The internal state is not modified by this so further data can be processed afterwards.
- Returns
final value
- Return type
- finalhex(byteorder='big')[source]¶
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.
- Returns
final value as hex string without leading ‘0x’.
- Return type
- finalbytes(byteorder='big')[source]¶
Return final checksum value as bytes. The internal state is not modified by this so further data can be processed afterwards.
- Returns
final value as bytes
- Return type
- value()[source]¶
Returns current intermediate value. Note that in general final() must be used to get the a final value.
- Returns
current value
- Return type
- classmethod calc(data, initvalue=None, **kwargs)[source]¶
Fully calculate CRC/checksum over given data.
- classmethod calchex(data, initvalue=None, byteorder='big', **kwargs)[source]¶
Fully calculate checksum over given data. Return result as hex string.
- Parameters
- Returns
final value as hex string without leading ‘0x’.
- Return type
crccheck.checksum module¶
Classes to calculated additive and XOR checksums.
License:
MIT License
Copyright (c) 2015-2022 by Martin Scharrer <martin.scharrer@web.de>
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.
- class crccheck.checksum.ChecksumBase(initvalue=0, byteorder='big')[source]¶
Bases:
CrccheckBase
Base class for all checksum classes.
- Parameters
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.
- class crccheck.checksum.Checksum32(initvalue=0, byteorder='big')[source]¶
Bases:
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.
- class crccheck.checksum.Checksum16(initvalue=0, byteorder='big')[source]¶
Bases:
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.
- class crccheck.checksum.Checksum8(initvalue=0, byteorder='big')[source]¶
Bases:
ChecksumBase
8-bit checksum.
Calculates 8-bit checksum by adding the input bytes.
- class crccheck.checksum.ChecksumXorBase(initvalue=0, byteorder='big')[source]¶
Bases:
ChecksumBase
Base class for all XOR checksum classes.
- class crccheck.checksum.ChecksumXor32(initvalue=0, byteorder='big')[source]¶
Bases:
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.
- class crccheck.checksum.ChecksumXor16(initvalue=0, byteorder='big')[source]¶
Bases:
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.
- class crccheck.checksum.ChecksumXor8(initvalue=0, byteorder='big')[source]¶
Bases:
ChecksumXorBase
8-bit XOR checksum.
Calculates 8-bit checksum by XOR-ing the input bytes.
- class crccheck.checksum.Checksum(width, initvalue=0, byteorder='big')[source]¶
Bases:
ChecksumBase
General additive checksum.
- class crccheck.checksum.ChecksumXor(width, initvalue=0, byteorder='big')[source]¶
Bases:
ChecksumXorBase
General XOR checksum.
crccheck.crc module¶
Classes to calculate CRCs (Cyclic Redundancy Check).
License:
MIT License
Copyright (c) 2015-2022 by Martin Scharrer <martin.scharrer@web.de>
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.
- class crccheck.crc.CrcBase(initvalue=None)[source]¶
Bases:
CrccheckBase
Abstract base class for all Cyclic Redundancy Checks (CRC) checksums
- crccheck.crc.find(classes=None, width=None, poly=None, initvalue=None, reflect_input=None, reflect_output=None, xor_output=None, check_result=None, residue=None)[source]¶
Find CRC classes which the matching properties.
- Parameters
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)
- crccheck.crc.identify(data, crc, width=None, classes=None, one=True)[source]¶
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.
- Parameters
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
- 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.
- Return type
If one is True
- class crccheck.crc.Crc(width, poly, initvalue=0, reflect_input=False, reflect_output=False, xor_output=0, check_result=0, residue=0)[source]¶
Bases:
CrcBase
Creates a new general (user-defined) CRC calculator instance.
- Parameters
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<<width)-1, i.e. “all-1s”.
reflect_input (bool) – If true the bit order of the input bytes are reflected first. This is to calculate the CRC like least-significant bit first systems will do it.
reflect_output (bool) – If true the bit order of the calculation result will be reflected before the XOR output stage.
xor_output (int) – The result is bit-wise XOR-ed with this value. Usually 0 (value stays the same) or (1<<width)-1, i.e. “all-1s” (invert value).
check_result (int) – The expected result for the check input “123456789” (= [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39]). This value is used for the selftest() method to verify proper operation.
residue (int) – The residue expected after calculating the CRC over the original data followed by the CRC of the original data. With initvalue=0 and xor_output=0 the residue calculates always to 0.
- calchex(data, initvalue=None, byteorder='big', **kwargs)[source]¶
Fully calculate checksum over given data. Return result as hex string.
- Parameters
- Returns
final value as hex string without leading ‘0x’.
- Return type
- class crccheck.crc.Crc8Base(initvalue=None)[source]¶
Bases:
CrcBase
CRC-8. Has optimised code for 8-bit CRCs and is used as base class for all other CRC with this width.
- class crccheck.crc.Crc16Base(initvalue=None)[source]¶
Bases:
CrcBase
CRC-16. Has optimised code for 16-bit CRCs and is used as base class for all other CRC with this width.
- class crccheck.crc.Crc32Base(initvalue=None)[source]¶
Bases:
CrcBase
CRC-32. Has optimised code for 32-bit CRCs and is used as base class for all other CRC with this width.
- class crccheck.crc.Crc5EpcC1G2(initvalue=None)[source]¶
Bases:
CrcBase
CRC-5/EPC-C1G2
Aliases: CRC-5/EPC
- crccheck.crc.Crc5Epc¶
alias of
Crc5EpcC1G2
- class crccheck.crc.Crc8I4321(initvalue=None)[source]¶
Bases:
Crc8Base
CRC-8/I-432-1
Aliases: CRC-8/ITU
- class crccheck.crc.Crc8MaximDow(initvalue=None)[source]¶
Bases:
Crc8Base
CRC-8/MAXIM-DOW
Aliases: CRC-8/MAXIM, DOW-CRC
- crccheck.crc.Crc8Maxim¶
alias of
Crc8MaximDow
- crccheck.crc.CrcDow¶
alias of
Crc8MaximDow
- class crccheck.crc.Crc8Tech3250(initvalue=None)[source]¶
Bases:
Crc8Base
CRC-8/TECH-3250
Aliases: CRC-8/AES, CRC-8/EBU
- crccheck.crc.Crc8Aes¶
alias of
Crc8Tech3250
- crccheck.crc.Crc8Ebu¶
alias of
Crc8Tech3250
- class crccheck.crc.Crc10Atm(initvalue=None)[source]¶
Bases:
CrcBase
CRC-10/ATM
Aliases: CRC-10, CRC-10/I-610
- class crccheck.crc.Crc11Flexray(initvalue=None)[source]¶
Bases:
CrcBase
CRC-11/FLEXRAY
Aliases: CRC-11
- crccheck.crc.Crc11¶
alias of
Crc11Flexray
- class crccheck.crc.Crc12Umts(initvalue=None)[source]¶
Bases:
CrcBase
CRC-12/UMTS
Aliases: CRC-12/3GPP
- class crccheck.crc.Crc16Arc(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/ARC
Aliases: ARC, CRC-16/LHA, CRC-IBM
- class crccheck.crc.Crc16DectR(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/DECT-R
Aliases: R-CRC-16
- crccheck.crc.Crc16R¶
alias of
Crc16DectR
- class crccheck.crc.Crc16DectX(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/DECT-X
Aliases: X-CRC-16
- crccheck.crc.Crc16X¶
alias of
Crc16DectX
- class crccheck.crc.Crc16Genibus(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/GENIBUS
Aliases: CRC-16/DARC, CRC-16/EPC, CRC-16/EPC-C1G2, CRC-16/I-CODE
- crccheck.crc.Crc16Darc¶
alias of
Crc16Genibus
- crccheck.crc.Crc16Epc¶
alias of
Crc16Genibus
- crccheck.crc.Crc16EpcC1G2¶
alias of
Crc16Genibus
- crccheck.crc.Crc16ICode¶
alias of
Crc16Genibus
- class crccheck.crc.Crc16Ibm3740(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/IBM-3740
Aliases: CRC-16/AUTOSAR, CRC-16/CCITT-FALSE
- crccheck.crc.Crc16Autosar¶
alias of
Crc16Ibm3740
- crccheck.crc.Crc16CcittFalse¶
alias of
Crc16Ibm3740
- class crccheck.crc.Crc16IbmSdlc(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/IBM-SDLC
Aliases: CRC-16/ISO-HDLC, CRC-16/ISO-IEC-14443-3-B, CRC-16/X-25, CRC-B, X-25
- crccheck.crc.Crc16IsoHdlc¶
alias of
Crc16IbmSdlc
- crccheck.crc.Crc16IsoIec144433B¶
alias of
Crc16IbmSdlc
- crccheck.crc.Crc16X25¶
alias of
Crc16IbmSdlc
- crccheck.crc.CrcB¶
alias of
Crc16IbmSdlc
- crccheck.crc.CrcX25¶
alias of
Crc16IbmSdlc
- class crccheck.crc.Crc16IsoIec144433A(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/ISO-IEC-14443-3-A
Aliases: CRC-A
- crccheck.crc.CrcA¶
alias of
Crc16IsoIec144433A
- class crccheck.crc.Crc16Kermit(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/KERMIT
Aliases: CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/V-41-LSB, CRC-CCITT, KERMIT
- crccheck.crc.Crc16Ccitt¶
alias of
Crc16Kermit
- crccheck.crc.Crc16CcittTrue¶
alias of
Crc16Kermit
- crccheck.crc.Crc16V41Lsb¶
alias of
Crc16Kermit
- crccheck.crc.CrcCcitt¶
alias of
Crc16Kermit
- crccheck.crc.CrcKermit¶
alias of
Crc16Kermit
- class crccheck.crc.Crc16MaximDow(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/MAXIM-DOW
Aliases: CRC-16/MAXIM
- crccheck.crc.Crc16Maxim¶
alias of
Crc16MaximDow
- crccheck.crc.Crc16Mcrf4XX¶
alias of
Crc16Mcrf4Xx
- crccheck.crc.Crcc16Mcrf4xx¶
alias of
Crc16Mcrf4Xx
- class crccheck.crc.Crc16Modbus(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/MODBUS
Aliases: MODBUS
- crccheck.crc.CrcModbus¶
alias of
Crc16Modbus
- class crccheck.crc.Crc16Profibus(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/PROFIBUS
Aliases: CRC-16/IEC-61158-2
- crccheck.crc.Crc16Iec611582¶
alias of
Crc16Profibus
- class crccheck.crc.Crc16SpiFujitsu(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/SPI-FUJITSU
Aliases: CRC-16/AUG-CCITT
- crccheck.crc.Crc16AugCcitt¶
alias of
Crc16SpiFujitsu
- class crccheck.crc.Crc16Umts(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/UMTS
Aliases: CRC-16/BUYPASS, CRC-16/VERIFONE
- class crccheck.crc.Crc16Xmodem(initvalue=None)[source]¶
Bases:
Crc16Base
CRC-16/XMODEM
Aliases: CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM
- crccheck.crc.Crc16Acorn¶
alias of
Crc16Xmodem
- crccheck.crc.Crc16Lte¶
alias of
Crc16Xmodem
- crccheck.crc.Crc16V41Msb¶
alias of
Crc16Xmodem
- crccheck.crc.CrcXmodem¶
alias of
Crc16Xmodem
- crccheck.crc.CrcZmodem¶
alias of
Crc16Xmodem
- crccheck.crc.Crc16¶
alias of
Crc16Xmodem
- class crccheck.crc.Crc24Openpgp(initvalue=None)[source]¶
Bases:
CrcBase
CRC-24/OPENPGP
Aliases: CRC-24
- crccheck.crc.Crc24¶
alias of
Crc24Openpgp
- crccheck.crc.Crc24OpenPgp¶
alias of
Crc24Openpgp
- class crccheck.crc.Crc32Base91D(initvalue=None)[source]¶
Bases:
Crc32Base
CRC-32/BASE91-D
Aliases: CRC-32D
- crccheck.crc.Crc32D¶
alias of
Crc32Base91D
- crccheck.crc.Crc32d¶
alias of
Crc32Base91D
- class crccheck.crc.Crc32Bzip2(initvalue=None)[source]¶
Bases:
Crc32Base
CRC-32/BZIP2
Aliases: CRC-32/AAL5, CRC-32/DECT-B, B-CRC-32
- crccheck.crc.Crc32Aal5¶
alias of
Crc32Bzip2
- crccheck.crc.Crc32DectB¶
alias of
Crc32Bzip2
- crccheck.crc.Crc32B¶
alias of
Crc32Bzip2
- class crccheck.crc.Crc32Cksum(initvalue=None)[source]¶
Bases:
Crc32Base
CRC-32/CKSUM
Aliases: CKSUM, CRC-32/POSIX
- crccheck.crc.CrcCksum¶
alias of
Crc32Cksum
- crccheck.crc.Crc32Posix¶
alias of
Crc32Cksum
- class crccheck.crc.Crc32Iscsi(initvalue=None)[source]¶
Bases:
Crc32Base
CRC-32/ISCSI
Aliases: CRC-32/BASE91-C, CRC-32/CASTAGNOLI, CRC-32/INTERLAKEN, CRC-32C
- crccheck.crc.Crc32Base91C¶
alias of
Crc32Iscsi
- crccheck.crc.Crc32Castagnoli¶
alias of
Crc32Iscsi
- crccheck.crc.Crc32Interlaken¶
alias of
Crc32Iscsi
- crccheck.crc.Crc32C¶
alias of
Crc32Iscsi
- crccheck.crc.Crc32c¶
alias of
Crc32Iscsi
- class crccheck.crc.Crc32IsoHdlc(initvalue=None)[source]¶
Bases:
Crc32Base
CRC-32/ISO-HDLC
Aliases: CRC-32, CRC-32/ADCCP, CRC-32/V-42, CRC-32/XZ, PKZIP
- crccheck.crc.Crc32¶
alias of
Crc32IsoHdlc
- crccheck.crc.Crc32Adccp¶
alias of
Crc32IsoHdlc
- crccheck.crc.Crc32V42¶
alias of
Crc32IsoHdlc
- crccheck.crc.Crc32Xz¶
alias of
Crc32IsoHdlc
- crccheck.crc.CrcPkzip¶
alias of
Crc32IsoHdlc
- class crccheck.crc.Crc32Jamcrc(initvalue=None)[source]¶
Bases:
Crc32Base
CRC-32/JAMCRC
Aliases: JAMCRC
- crccheck.crc.CrcJamcrc¶
alias of
Crc32Jamcrc
- class crccheck.crc.Crc64Ecma182(initvalue=None)[source]¶
Bases:
CrcBase
CRC-64/ECMA-182
Aliases: CRC-64
- crccheck.crc.Crc64¶
alias of
Crc64Ecma182
Module contents¶
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/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 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 <martin.scharrer@web.de>
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.