-
-
Save jed/1200689 to your computer and use it in GitHub Desktop.
fletcher 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,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} |
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": "fletcher checksum", | |
"description": "a javascript port of wikipedia's example C implementation of the fletcher checksum", | |
"keywords": [ | |
"fletcher", | |
"checksum", | |
"hash" | |
] | |
} |
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>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> |
good catch! tho i don't think i need to reverse the order, do i?
fletcher('foo2e2e2')
// 166 it's ok ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return b|c<<8
is 1 byte shorter ;)