Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active September 23, 2019 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildsunrise/632bb4db2a98f563fb48c82710fc2290 to your computer and use it in GitHub Desktop.
Save mildsunrise/632bb4db2a98f563fb48c82710fc2290 to your computer and use it in GitHub Desktop.
CRC32
const table = new Int32Array(256).map((_,n) => [...Array(8)]
.reduce(c => (c>>>1) ^ ((c&1) * 0xEDB88320), n))
const fn = (C, b) => (C>>>8) ^ table[(C^b) & 0xFF]
const crc = (x, seed) => ~x.reduce(fn, ~seed)
// Example:
crc( Buffer.from('Hello') ) === 0xF7D18982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment