CRC implementation with configurable polynomials.

A pure TypeScript CRC library supporting CRC8, CRC16, CRC32, and CRC64.

Each width is exposed at three layers:

  • One-shot: crc8 / crc16 / crc32 / crc64 — convenience helpers that use a conventional default polynomial.
  • Factory: createCrc8 / etc. — return a reusable function bound to a specific polynomial (each call builds the lookup table).
  • Memoized factory: memoizedCreateCrc8 / etc. — same as the factory, but repeated calls with the same polynomial reuse the cached function.

Examples

One-shot helpers with default polynomials

import { assertEquals } from "@std/assert";
import { crc32, crc64 } from "@hertzg/crc";

assertEquals(crc32(new TextEncoder().encode("123456789")), 0xcbf43926);
assertEquals(crc64(new TextEncoder().encode("123456789")), 0x995dc9bbdf1939fan);

Factory with a custom polynomial (CRC32C / Castagnoli)

import { assertEquals } from "@std/assert";
import { createCrc32, CRC32C_POLYNOMIAL } from "@hertzg/crc";

const crc32c = createCrc32(CRC32C_POLYNOMIAL);

assertEquals(crc32c(new TextEncoder().encode("123456789")), 0xe3069283);

Functions

Variables

v
CRC16_CCITT_POLYNOMIAL: 33800

CRC16-CCITT polynomial (X.25, HDLC, Bluetooth).

v
CRC16_IBM_POLYNOMIAL: 40961

CRC16-IBM/ANSI polynomial (USB, Modbus).

v
CRC32_POLYNOMIAL: 3988292384

Standard CRC32 polynomial (ISO 3309, PNG, ZIP, gzip).

v
CRC32C_POLYNOMIAL: 2197175160

CRC32C polynomial (iSCSI, SCTP, ext4). Also known as Castagnoli.

v
CRC32K_POLYNOMIAL: 3945912366

CRC32K polynomial (Koopman). Designed for improved Hamming-distance coverage.

v
CRC64_ECMA_POLYNOMIAL: 14514072000185962306

CRC64-ECMA polynomial (XZ, 7z).

v
CRC64_ISO_POLYNOMIAL: 15564440312192434176

CRC64-ISO polynomial (ISO 3309).

v
CRC8_CCITT_POLYNOMIAL: 224

CRC8-CCITT polynomial (ATM HEC).

v
CRC8_MAXIM_POLYNOMIAL: 140

CRC8-Maxim/Dallas polynomial (1-Wire, iButton).