Skip to content

Instantly share code, notes, and snippets.

@jed
Forked from 140bytes/LICENSE.txt
Created Sep 7, 2011
Embed
What would you like to do?
adler32 checksum
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}
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.
{
"name": "adler32",
"description": "a javascript port of wikipedia's example C implementation of Adler32",
"keywords": [
"checksum",
"hash",
"adler32"
]
}
<!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>
@subzey

This comment has been minimized.

Copy link

@subzey subzey commented Sep 7, 2011

@jed, Nice one!

Placeholder arguments aren't panacea for js minification, straightforward var declaration is 2 bytes shorter:

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}
@jed

This comment has been minimized.

Copy link
Owner Author

@jed jed commented Sep 7, 2011

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.

@p01

This comment has been minimized.

Copy link

@p01 p01 commented Sep 7, 2011

Also, return c|d<<16 is 1 byte shorter

@jed

This comment has been minimized.

Copy link
Owner Author

@jed jed commented Sep 7, 2011

thanks again, @p01!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment