checkdigit.crc.calculate

checkdigit.crc.calculate(data: str, polynomial: str, pad: str = '0') str[source]

Adds a parity part onto the end of a block of data.

Parameters:
  • data – A string containing binary digits of any length

  • polynomial – A string of binary digits representing the polynomial being used

  • pad – “1” or “0” or nothing to be used to pad the data (defaults to 0)

Returns:

Check Value that should be appended to the stream

Return type:

str

Examples

>>> from checkdigit import crc
>>> crc.calculate("1010", "1011")
'011'
>>> crc.calculate("100110010100111101111101", "11010111101")
'0010001100'