MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / fletcher16

Function fletcher16

hashes/fletcher16.py:13–30  ·  view source on GitHub ↗

Loop through every character in the data and add to two sums. >>> fletcher16('hello world') 6752 >>> fletcher16('onethousandfourhundredthirtyfour') 28347 >>> fletcher16('The quick brown fox jumps over the lazy dog.') 5655

(text: str)

Source from the content-addressed store, hash-verified

11
12
13def fletcher16(text: str) -> int:
14 """
15 Loop through every character in the data and add to two sums.
16
17 >>> fletcher16('hello world')
18 6752
19 >>> fletcher16('onethousandfourhundredthirtyfour')
20 28347
21 >>> fletcher16('The quick brown fox jumps over the lazy dog.')
22 5655
23 """
24 data = bytes(text, "ascii")
25 sum1 = 0
26 sum2 = 0
27 for character in data:
28 sum1 = (sum1 + character) % 255
29 sum2 = (sum1 + sum2) % 255
30 return (sum2 << 8) | sum1
31
32
33if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected