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)
| 11 | |
| 12 | |
| 13 | def 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 | |
| 33 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected