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.

Parameters
  • width (int) – bitwidth

  • value (int) – value to reflect

exception crccheck.base.CrccheckError[source]

Bases: Exception

General checksum error exception

class crccheck.base.CrccheckBase(initvalue=None, **kwargs)[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.

classmethod initvalue()[source]

Getter for initvalue.

classmethod check_result()[source]

Getter for check_result.

classmethod check_data()[source]

Getter for check_data.

classmethod width()[source]
classmethod bytewidth()[source]
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

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

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

int

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

str

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

bytes

value()[source]

Returns current intermediate value. Note that in general final() must be used to get the final value.

Returns

current value

Return type

int

classmethod calc(data, initvalue=None, **kwargs)[source]

Fully calculate CRC/checksum over given data.

Parameters
  • 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.

Returns

final value

Return type

int

classmethod calchex(data, initvalue=None, byteorder='big', **kwargs)[source]

Fully calculate checksum over given data. Return result as hex string.

Parameters
  • 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.

Returns

final value as hex string without leading ‘0x’.

Return type

str

classmethod calcbytes(data, initvalue=None, byteorder='big', **kwargs)[source]

Fully calculate checksum over given data. Return result as bytearray.

Parameters
  • 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.

Returns

final value as bytes

Return type

bytes

classmethod selftest(data=None, expectedresult=None, **kwargs)[source]

Selftest method for automated tests.

Parameters
Raises

CrccheckError – if result is not as expected

copy()[source]

Creates a copy of the Crc/Checksum instance. This can be used to efficiently compute the CRC/checksum of data sharing common initial part.

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.

classmethod mask()[source]

Getter for mask.

classmethod check_result(byteorder='big')[source]

Getter for check_result. :param byteorder: Either ‘big’ (default) or ‘little’.

Should only be used as a keyword argument for upwards compatiblity.

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

Returns

self

classmethod selftest(data=None, expectedresult=None, byteorder='big')[source]

Selftest method for automated tests.

Parameters
  • 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

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.

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

Returns

self

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.

Parameters
  • 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.

class crccheck.checksum.ChecksumXor(width, initvalue=0, byteorder='big')[source]

Bases: ChecksumXorBase

General XOR checksum.

Parameters
  • 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.

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, **kwargs)[source]

Bases: CrccheckBase

Abstract base class for all Cyclic Redundancy Checks (CRC) checksums

classmethod poly()[source]

Getter for polynominal value.

classmethod reflect_input()[source]

Getter for reflect_input.

classmethod reflect_output()[source]

Getter for reflect_output.

classmethod xor_output()[source]

Getter for xor_output value.

classmethod residue()[source]

Getter for residue value.

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

Returns

self

final()[source]

Return final CRC value.

Returns

final CRC value

Return type

int

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.

calc(data, initvalue=None, **kwargs)[source]

Fully calculate CRC/checksum over given data.

Parameters
  • 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.

Returns

final value

Return type

int

calchex(data, initvalue=None, byteorder='big', **kwargs)[source]

Fully calculate checksum over given data. Return result as hex string.

Parameters
  • 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.

Returns

final value as hex string without leading ‘0x’.

Return type

str

calcbytes(data, initvalue=None, byteorder='big', **kwargs)[source]

Fully calculate checksum over given data. Return result as bytearray.

Parameters
  • 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.

Returns

final value as bytes

Return type

bytes

selftest(data=None, expectedresult=None, **kwargs)[source]

Selftest method for automated tests.

Parameters
Raises

CrccheckError – if result is not as expected

class crccheck.crc.Crc8Base(initvalue=None, **kwargs)[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.

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

Returns

self

class crccheck.crc.Crc16Base(initvalue=None, **kwargs)[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.

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

Returns

self

class crccheck.crc.Crc32Base(initvalue=None, **kwargs)[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.

process(data)[source]

Process given data.

Parameters

data (bytes, bytearray or list of ints [0-255]) – input data to process.

Returns

self

crccheck.crc.crccls(width=None, poly=None, initvalue=None, reflect_input=None, reflect_output=None, xor_output=None, check_result=None, residue=None, clsname=None, name=None, basecls=None)[source]
class crccheck.crc.Crc3Gsm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-3/GSM

class crccheck.crc.Crc3Rohc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-3/ROHC

class crccheck.crc.Crc4G704(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-4/G-704

Aliases: CRC-4/ITU

crccheck.crc.Crc4Itu

alias of Crc4G704

class crccheck.crc.Crc4Interlaken(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-4/INTERLAKEN

class crccheck.crc.Crc5EpcC1G2(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-5/EPC-C1G2

Aliases: CRC-5/EPC

crccheck.crc.Crc5Epc

alias of Crc5EpcC1G2

class crccheck.crc.Crc5G704(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-5/G-704

Aliases: CRC-5/ITU

crccheck.crc.Crc5Itu

alias of Crc5G704

class crccheck.crc.Crc5Usb(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-5/USB

class crccheck.crc.Crc6Cdma2000A(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-6/CDMA2000-A

class crccheck.crc.Crc6Cdma2000B(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-6/CDMA2000-B

class crccheck.crc.Crc6Darc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-6/DARC

class crccheck.crc.Crc6G704(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-6/G-704

Aliases: CRC-6/ITU

crccheck.crc.Crc6Itu

alias of Crc6G704

class crccheck.crc.Crc6Gsm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-6/GSM

class crccheck.crc.Crc7Mmc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-7/MMC

Aliases: CRC-7

crccheck.crc.Crc7

alias of Crc7Mmc

class crccheck.crc.Crc7Rohc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-7/ROHC

class crccheck.crc.Crc7Umts(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-7/UMTS

class crccheck.crc.Crc8Autosar(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/AUTOSAR

class crccheck.crc.Crc8Bluetooth(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/BLUETOOTH

class crccheck.crc.Crc8Cdma2000(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/CDMA2000

class crccheck.crc.Crc8Darc(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/DARC

class crccheck.crc.Crc8DvbS2(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/DVB-S2

class crccheck.crc.Crc8GsmA(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/GSM-A

class crccheck.crc.Crc8GsmB(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/GSM-B

class crccheck.crc.Crc8Hitag(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/HITAG

class crccheck.crc.Crc8I4321(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/I-432-1

Aliases: CRC-8/ITU

crccheck.crc.Crc8Itu

alias of Crc8I4321

class crccheck.crc.Crc8ICode(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/I-CODE

class crccheck.crc.Crc8Lte(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/LTE

class crccheck.crc.Crc8MaximDow(initvalue=None, **kwargs)[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.Crc8MifareMad(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/MIFARE-MAD

class crccheck.crc.Crc8Nrsc5(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/NRSC-5

class crccheck.crc.Crc8Opensafety(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/OPENSAFETY

class crccheck.crc.Crc8Rohc(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/ROHC

class crccheck.crc.Crc8SaeJ1850(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/SAE-J1850

class crccheck.crc.Crc8Smbus(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/SMBUS

Aliases: CRC-8

crccheck.crc.Crc8

alias of Crc8Smbus

class crccheck.crc.Crc8Tech3250(initvalue=None, **kwargs)[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.Crc8Wcdma(initvalue=None, **kwargs)[source]

Bases: Crc8Base

CRC-8/WCDMA

class crccheck.crc.Crc10Atm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-10/ATM

Aliases: CRC-10, CRC-10/I-610

crccheck.crc.Crc10

alias of Crc10Atm

crccheck.crc.Crc10I610

alias of Crc10Atm

class crccheck.crc.Crc10Cdma2000(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-10/CDMA2000

class crccheck.crc.Crc10Gsm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-10/GSM

class crccheck.crc.Crc11Flexray(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-11/FLEXRAY

Aliases: CRC-11

crccheck.crc.Crc11

alias of Crc11Flexray

class crccheck.crc.Crc11Umts(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-11/UMTS

class crccheck.crc.Crc12Cdma2000(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-12/CDMA2000

class crccheck.crc.Crc12Dect(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-12/DECT

Aliases: CRC-12-X

crccheck.crc.Crc12X

alias of Crc12Dect

class crccheck.crc.Crc12Gsm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-12/GSM

class crccheck.crc.Crc12Umts(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-12/UMTS

Aliases: CRC-12/3GPP

crccheck.crc.Crc123Gpp

alias of Crc12Umts

class crccheck.crc.Crc13Bbc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-13/BBC

class crccheck.crc.Crc14Darc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-14/DARC

class crccheck.crc.Crc14Gsm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-14/GSM

class crccheck.crc.Crc15Can(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-15/CAN

Aliases: CRC-15

crccheck.crc.Crc15

alias of Crc15Can

class crccheck.crc.Crc15Mpt1327(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-15/MPT1327

class crccheck.crc.Crc16Arc(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/ARC

Aliases: ARC, CRC-16/LHA, CRC-IBM

crccheck.crc.CrcArc

alias of Crc16Arc

crccheck.crc.Crc16Lha

alias of Crc16Arc

crccheck.crc.CrcIbm

alias of Crc16Arc

class crccheck.crc.Crc16Cdma2000(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/CDMA2000

class crccheck.crc.Crc16Cms(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/CMS

class crccheck.crc.Crc16Dds110(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/DDS-110

class crccheck.crc.Crc16DectR(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/DECT-R

Aliases: R-CRC-16

crccheck.crc.Crc16R

alias of Crc16DectR

class crccheck.crc.Crc16DectX(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/DECT-X

Aliases: X-CRC-16

crccheck.crc.Crc16X

alias of Crc16DectX

class crccheck.crc.Crc16Dnp(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/DNP

class crccheck.crc.Crc16En13757(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/EN-13757

class crccheck.crc.Crc16Genibus(initvalue=None, **kwargs)[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.Crc16Gsm(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/GSM

class crccheck.crc.Crc16Ibm3740(initvalue=None, **kwargs)[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, **kwargs)[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, **kwargs)[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, **kwargs)[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.Crc16Lj1200(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/LJ1200

class crccheck.crc.Crc16M17(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/M17

class crccheck.crc.Crc16MaximDow(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/MAXIM-DOW

Aliases: CRC-16/MAXIM

crccheck.crc.Crc16Maxim

alias of Crc16MaximDow

class crccheck.crc.Crc16Mcrf4Xx(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/MCRF4XX

crccheck.crc.Crc16Mcrf4XX

alias of Crc16Mcrf4Xx

crccheck.crc.Crcc16Mcrf4xx

alias of Crc16Mcrf4Xx

class crccheck.crc.Crc16Modbus(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/MODBUS

Aliases: MODBUS

crccheck.crc.CrcModbus

alias of Crc16Modbus

class crccheck.crc.Crc16Nrsc5(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/NRSC-5

class crccheck.crc.Crc16OpensafetyA(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/OPENSAFETY-A

class crccheck.crc.Crc16OpensafetyB(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/OPENSAFETY-B

class crccheck.crc.Crc16Profibus(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/PROFIBUS

Aliases: CRC-16/IEC-61158-2

crccheck.crc.Crc16Iec611582

alias of Crc16Profibus

class crccheck.crc.Crc16Riello(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/RIELLO

class crccheck.crc.Crc16SpiFujitsu(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/SPI-FUJITSU

Aliases: CRC-16/AUG-CCITT

crccheck.crc.Crc16AugCcitt

alias of Crc16SpiFujitsu

class crccheck.crc.Crc16T10Dif(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/T10-DIF

class crccheck.crc.Crc16Teledisk(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/TELEDISK

class crccheck.crc.Crc16Tms37157(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/TMS37157

class crccheck.crc.Crc16Umts(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/UMTS

Aliases: CRC-16/BUYPASS, CRC-16/VERIFONE

crccheck.crc.Crc16Buypass

alias of Crc16Umts

crccheck.crc.Crc16Verifone

alias of Crc16Umts

class crccheck.crc.Crc16Usb(initvalue=None, **kwargs)[source]

Bases: Crc16Base

CRC-16/USB

class crccheck.crc.Crc16Xmodem(initvalue=None, **kwargs)[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.Crc17CanFd(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-17/CAN-FD

class crccheck.crc.Crc21CanFd(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-21/CAN-FD

class crccheck.crc.Crc24Ble(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/BLE

class crccheck.crc.Crc24FlexrayA(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/FLEXRAY-A

class crccheck.crc.Crc24FlexrayB(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/FLEXRAY-B

class crccheck.crc.Crc24Interlaken(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/INTERLAKEN

class crccheck.crc.Crc24LteA(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/LTE-A

class crccheck.crc.Crc24LteB(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/LTE-B

class crccheck.crc.Crc24Openpgp(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/OPENPGP

Aliases: CRC-24

crccheck.crc.Crc24

alias of Crc24Openpgp

crccheck.crc.Crc24OpenPgp

alias of Crc24Openpgp

class crccheck.crc.Crc24Os9(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-24/OS-9

class crccheck.crc.Crc30Cdma(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-30/CDMA

class crccheck.crc.Crc31Philips(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-31/PHILIPS

class crccheck.crc.Crc32Aixm(initvalue=None, **kwargs)[source]

Bases: Crc32Base

CRC-32/AIXM

Aliases: CRC-32Q

crccheck.crc.Crc32Q

alias of Crc32Aixm

crccheck.crc.Crc32q

alias of Crc32Aixm

class crccheck.crc.Crc32Autosar(initvalue=None, **kwargs)[source]

Bases: Crc32Base

CRC-32/AUTOSAR

class crccheck.crc.Crc32Base91D(initvalue=None, **kwargs)[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, **kwargs)[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.Crc32CdRomEdc(initvalue=None, **kwargs)[source]

Bases: Crc32Base

CRC-32/CD-ROM-EDC

class crccheck.crc.Crc32Cksum(initvalue=None, **kwargs)[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, **kwargs)[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, **kwargs)[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, **kwargs)[source]

Bases: Crc32Base

CRC-32/JAMCRC

Aliases: JAMCRC

crccheck.crc.CrcJamcrc

alias of Crc32Jamcrc

class crccheck.crc.Crc32Mef(initvalue=None, **kwargs)[source]

Bases: Crc32Base

CRC-32/MEF

class crccheck.crc.Crc32Mpeg2(initvalue=None, **kwargs)[source]

Bases: Crc32Base

CRC-32/MPEG-2

class crccheck.crc.Crc32Xfer(initvalue=None, **kwargs)[source]

Bases: Crc32Base

CRC-32/XFER

Aliases: XFER

crccheck.crc.CrcXfer

alias of Crc32Xfer

class crccheck.crc.Crc40Gsm(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-40/GSM

class crccheck.crc.Crc64Ecma182(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-64/ECMA-182

Aliases: CRC-64

crccheck.crc.Crc64

alias of Crc64Ecma182

class crccheck.crc.Crc64GoIso(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-64/GO-ISO

class crccheck.crc.Crc64Ms(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-64/MS

class crccheck.crc.Crc64Redis(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-64/REDIS

class crccheck.crc.Crc64We(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-64/WE

class crccheck.crc.Crc64Xz(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-64/XZ

Aliases: CRC-64/GO-ECMA

crccheck.crc.Crc64GoEcma

alias of Crc64Xz

class crccheck.crc.Crc82Darc(initvalue=None, **kwargs)[source]

Bases: CrcBase

CRC-82/DARC

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.