Created
October 15, 2024 09:11
-
-
Save alekstar79/3cc0ba7c26130f47319e7327f4cecd43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hash = (() => { | |
const makeCRCTable = () => { | |
let c | |
const crcTable = [] | |
for(let n = 0; n < 256; n++) { | |
c = n; | |
for(let k = 0; k < 8; k++) { | |
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)) | |
} | |
crcTable[n] = c | |
} | |
return crcTable | |
} | |
const crcTable = makeCRCTable() | |
const crc32 = (str) => { | |
let crc = 0 ^ (-1) | |
for (let i = 0; i < str.length; i++ ) { | |
crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF] | |
} | |
return (crc ^ (-1)) >>> 0 | |
} | |
return (string) => { | |
return crc32(string).toString(16) | |
} | |
})() | |
hash('Helo World') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment