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?
fletcher checksum
function(a,b,c,d,e){for(b=c=d=0;e=a.charCodeAt(d++);c=(c+b)%255)b=(b+e)%255;return c<<8|b}
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": "fletcher checksum",
"description": "a javascript port of wikipedia's example C implementation of the fletcher checksum",
"keywords": [
"fletcher",
"checksum",
"hash"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>51599</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
var fletcher = function(a,b,c,d,e){for(b=c=d=0;e=a.charCodeAt(d++);c=(c+b)%255)b=(b+e)%255;return c<<8|b}
document.getElementById( "ret" ).innerHTML = fletcher("140byt.es is totally rad!")
</script>
@p01

This comment has been minimized.

Copy link

@p01 p01 commented Sep 7, 2011

return b|c<<8 is 1 byte shorter ;)

@jed

This comment has been minimized.

Copy link
Owner Author

@jed jed commented Sep 7, 2011

good catch! tho i don't think i need to reverse the order, do i?

@monolithed

This comment has been minimized.

Copy link

@monolithed monolithed commented Dec 5, 2013

fletcher('foo2e2e2') // 166 it's ok ?

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