Checksum

Checksum consists of htf.checksum.CRC.

CRC

htf.checksum.CRC allows users to easily calculate crc checksums over data.

class htf.checksum.CRC(width, polynomial, reflect_input, initial_value, reflect_output, xor_output)

A configurable CRC calculator.

The CRC constructor.

Parameters
  • width (int) – the CRC’s width in bits

  • polynomial (int) – the CRC’s polynomial

  • reflect_input (bool) – if set to True input is reflected

  • initial_value (int) – the initial value

  • reflect_output (bool) – if set to True output is reflected

  • xor_output (int) – xor all outputs with xor_output

calculate(data)

Calculates the crc over data bit by bit.

Parameters

data (bytes or iterable of int) – the input data to be used for the crc calculation

Returns

the calculated crc for data

Return type

int

Example

This example calculates a CRC-16 over "123456789".

from __future__ import \
    absolute_import, division, print_function, unicode_literals


from htf.checksum import CRC

crc16 = CRC(width=16,
            polynomial=0x8005,
            reflect_input=True,
            initial_value=0,
            reflect_output=True,
            xor_output=0)

result = crc16.calculate(b"123456789")
assert result == 0xBB3D