Skip to content
heff

std.adler32

Adler-32, the checksum of RFC 1950 that zlib keeps: two sums of the bytes, each modulo 65521, the largest prime below 65536 — a, 1 and each byte, and b, each a so far — as b times 65536 and a, Go’s adler32.Checksum. It is quicker than a CRC-32, and weaker over few bytes; it finds bytes changed by accident, not on purpose.

import bytes as Bytes
import std.adler32 as Adler32
-- | whether a zlib stream's data is what its trailer says it was
unchanged : Bytes -> UInt32 -> Bool
unchanged content recorded = Adler32.checksum content == recorded

checksum

checksum : Bytes -> UInt32

The Adler-32 of the bytes: of “Wikipedia”, 0x11e60398.

>>> checksum (Bytes.fromString "Wikipedia") == 0x11e60398
True
>>> checksum Bytes.empty
1
>>> checksum (Bytes.fromString "The quick brown fox jumps over the lazy dog") == 0x5bdc0fda
True
>>> checksum (Bytes.fromList (List.replicate 100000 255)) == 0x149a302c
True