Created
March 31, 2023 09:54
-
-
Save dnutiu/5b13c7355dcab3623f722b4af2fa14f2 to your computer and use it in GitHub Desktop.
crc32 implementation, source: https://stackoverflow.com/a/18639999/4092044
This file contains 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
var makeCRCTable = function(){ | |
var c; | |
var crcTable = []; | |
for(var n =0; n < 256; n++){ | |
c = n; | |
for(var k =0; k < 8; k++){ | |
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); | |
} | |
crcTable[n] = c; | |
} | |
return crcTable; | |
} | |
var crc32 = function(str) { | |
var crcTable = window.crcTable || (window.crcTable = makeCRCTable()); | |
var crc = 0 ^ (-1); | |
for (var i = 0; i < str.length; i++ ) { | |
crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF]; | |
} | |
return (crc ^ (-1)) >>> 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment