Created
March 4, 2014 00:35
-
-
Save globby/9337839 to your computer and use it in GitHub Desktop.
The Fletcher16, Fletcher32 and Fletcher64 algorithms
This file contains 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
def Fletcher16(string): | |
a = map(ord,string) | |
b = [sum(a[:i])%255 for i in range(len(a)+1)] | |
return (sum(b) << 8) | max(b) | |
def Fletcher32(string): | |
a = map(ord,string) | |
b = [sum(a[:i])%65535 for i in range(len(a)+1)] | |
return (sum(b) << 16) | max(b) | |
def Fletcher64(string): | |
a = map(ord,string) | |
b = [sum(a[:i])%4294967295 for i in range(len(a)+1)] | |
return (sum(b) << 32) | max(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you have to apply modulo before summing.