-
-
Save jed/1200559 to your computer and use it in GitHub Desktop.
adler32 checksum
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
function(a){for(var b=65521,c=1,d=0,e=0,f;f=a.charCodeAt(e++);d=(d+c)%b)c=(c+f)%b;return d<<16|c} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Jed Schmidt <http://jed.is> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "adler32", | |
"description": "a javascript port of wikipedia's example C implementation of Adler32", | |
"keywords": [ | |
"checksum", | |
"hash", | |
"adler32" | |
] | |
} |
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
<!DOCTYPE html> | |
<title>Foo</title> | |
<div>Expected value: <b>1802963080</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
var adler32 = function(a){for(var b=65521,c=1,d=0,e=0,f;f=a.charCodeAt(e++);d=(d+c)%b)c=(c+f)%b;return d<<16|c} | |
document.getElementById( "ret" ).innerHTML = adler32("140byt.es is totally rad!") | |
</script> |
great point, @subzey, and very easy to forget. i'll fix this on the fletcher too.
EDIT: actually, it looks like fletcher doesn't need it.
Also, return c|d<<16
is 1 byte shorter
thanks again, @p01!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jed, Nice one!
Placeholder arguments aren't panacea for js minification, straightforward
var
declaration is 2 bytes shorter: