crc — CRC Computation
The crc module computes CRC16 and CRC32 checksums over byte-like
buffers. Each function may be called with only data to start a new CRC,
or with a previous value to continue an existing CRC across multiple
buffers.
Example:
import crc
c = crc.crc32(b"hello ")
c = crc.crc32(b"world", value=c)
print(hex(c))
Functions
- crc.crc16(data: bytes, *, value: int = None) int
Computes a CRC16 checksum over
data, which must be a buffer-like object (e.g.bytes,bytearray, ormemoryview).If
valueis not provided, a new CRC16 is started overdataand returned. Ifvalueis provided, it is used as the previous CRC16 state and updated withdatabefore being returned, allowing CRC16 computation across multiple buffers. Only the lower 16 bits ofvalueare used.Returns the resulting CRC16 as an
int.
- crc.crc32(data: bytes, *, value: int = None) int
Computes a CRC32 checksum over
data, which must be a buffer-like object (e.g.bytes,bytearray, ormemoryview).If
valueis not provided, a new CRC32 is started overdataand returned. Ifvalueis provided, it is used as the previous CRC32 state and updated withdatabefore being returned, allowing CRC32 computation across multiple buffers.Returns the resulting CRC32 as an
int.