adler32 checksum in javascript

function(a,b,c,d,e,f){for(b=65521,c=1,d=e=0;f=a.charCodeAt(e++);d=(d+c)%b)c=(c+f)%b;return(d<

example:

<!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,b,c,d,e,f){for(b=65521,c=1,d=e=0;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>
{
  “name”: “adler32”,
  “description”: “a javascript port of wikipedia’s example C implementation of Adler32”,
  “keywords”: [
    “checksum”,
    “hash”,
    “adler32”
  ]
}

http://140byt.es/

This entry was posted in Code Snippets and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s