CRC32
1 API Reference
crc32-bytes
crc32-string/  utf8
crc32-string/  latin-1
crc32-string/  locale
crc32-input-port
2 Low-level API
crc32-initial-value
crc32-update
crc32-finalize
3 Examples
8.18.0.13

CRC32🔗ℹ

jrtxio

 (require crc32) package: crc32

This package provides CRC32 (IEEE 802.3 standard) checksum computation functions.

CRC32 is commonly used for error detection in network transmissions and file integrity checks.

1 API Reference🔗ℹ

procedure

(crc32-bytes bs)  exact-nonnegative-integer?

  bs : bytes?
Computes the CRC32 checksum of the given byte string.

Examples:
> (require crc32)
> (crc32-bytes #"abc")

891568578

> (number->string (crc32-bytes #"abc") 16)

"352441c2"

procedure

(crc32-string/utf8 str)  exact-nonnegative-integer?

  str : string?
Computes the CRC32 checksum of the UTF-8 encoding of the given string.

Examples:
> (require crc32)
> (crc32-string/utf8 "hello")

907060870

> (number->string (crc32-string/utf8 "hello") 16)

"3610a686"

Computes the CRC32 checksum of the Latin-1 encoding of the given string.

procedure

(crc32-string/locale str)  exact-nonnegative-integer?

  str : string?
Computes the CRC32 checksum of the locale encoding of the given string.

Computes the CRC32 checksum of all bytes read from the input port.

Examples:
> (require crc32)
> (crc32-input-port (open-input-bytes #"test data"))

3540561586

2 Low-level API🔗ℹ

For incremental computation or when you need more control over the process:

The initial value for CRC32 computation (4294967295).

Updates the CRC32 accumulator with a single byte.

Finalizes the CRC32 computation by applying the final XOR.

3 Examples🔗ℹ

Examples:
> (require crc32)
> (crc32-bytes #"hello world")

222957957

> (define acc crc32-initial-value)
> (set! acc (crc32-update acc 104))
> (set! acc (crc32-update acc 101))
> (set! acc (crc32-update acc 108))
> (set! acc (crc32-update acc 108))
> (set! acc (crc32-update acc 111))
> (crc32-finalize acc)

907060870

> (crc32-bytes #"hello")

907060870