Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 4, 2014 00:35

Revisions

  1. globby created this gist Mar 4, 2014.
    12 changes: 12 additions & 0 deletions Fletcher.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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)