habitat.utils.checksums

Various checksum calculation utilities.

Functions

crc16_ccitt(data) Calculate the CRC16 CCITT checksum of data.
fletcher_16(data[, modulus]) Calculate the Fletcher-16 checksum of data, default modulus 255.
op_xor xor(a, b) – Same as a ^ b.
xor(data) Calculate the XOR checksum of data.
habitat.utils.checksums.crc16_ccitt(data)[source]

Calculate the CRC16 CCITT checksum of data.

(CRC16 CCITT: start 0xFFFF, poly 0x1021)

Returns an upper case, zero-filled hex string with no prefix such as 0A1B.

>>> crc16_ccitt("hello,world")
'E408'
habitat.utils.checksums.xor(data)[source]

Calculate the XOR checksum of data.

Returns an upper case, zero-filled hex string with no prefix such as 01.

>>> xor("hello,world")
'2C'
habitat.utils.checksums.fletcher_16(data, modulus=255)[source]

Calculate the Fletcher-16 checksum of data, default modulus 255.

Returns an upper case, zero-filled hex string with no prefix such as 0A1B.

>>> fletcher_16("hello,world")
'6C62'
>>> fletcher_16("hello,world", 256)
'6848'