Skip to content

Instantly share code, notes, and snippets.

@nikolaifedorov
Forked from volodymyr-mykhailyk/gist:2923823
Last active August 29, 2015 13:56
Show Gist options
  • Save nikolaifedorov/9185963 to your computer and use it in GitHub Desktop.
Save nikolaifedorov/9185963 to your computer and use it in GitHub Desktop.
function adler32(data) {
var MOD_ADLER = 65521;
var a = 1, b = 0;
var index;
// Process each byte of the data in order
for (index = 0; index < data.length; ++index) {
a = (a + data.charCodeAt(index)) % MOD_ADLER;
b = (b + a) % MOD_ADLER;
}
//adler checksum as integer;
var adler = a | (b << 16);
//adler checksum as byte array
return String.fromCharCode( ((adler >> 24) & 0xff),
((adler >> 16) & 0xff),
((adler >> 8) & 0xff),
((adler >> 0) & 0xff) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment