Skip to content
heff

std.crc32

CRC-32, the checksum of IEEE 802.3 that zlib, gzip, zip and PNG keep: the bytes’ remainder by the polynomial 0x04c11db7, its bits reflected (0xedb88320), begun at and inverted by 0xffffffff — Go’s crc32.ChecksumIEEE. It finds bytes changed by accident, not on purpose: anyone can make bytes of a given CRC. Written in heff, a byte at a time by a table of 256.

import bytes as Bytes
import std.crc32 as CRC32
-- | whether a zip entry's content is what its header says it was
unchanged : Bytes -> UInt32 -> Bool
unchanged content recorded = CRC32.checksum content == recorded

checksum

checksum : Bytes -> UInt32

The CRC-32 of the bytes: of “123456789”, 0xcbf43926.

>>> checksum (Bytes.fromString "123456789")
3421780262
>>> checksum (Bytes.fromString "123456789") == 0xcbf43926
True
>>> checksum Bytes.empty
0
>>> checksum (Bytes.fromString "The quick brown fox jumps over the lazy dog") == 0x414fa339
True