the fletcher checksum is an algorithm for computing a positiondependent checksum devised by john g fletcher 19342012 at lawrence livermore labs in the late 1970s 1 the objective of the fletcher checksum was to provide errordetection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques source https en wikipedia orgwikifletcher27schecksum 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 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
def fletcher16(text: str) -> int:
    
    data = bytes(text, "ascii")
    sum1 = 0
    sum2 = 0
    for character in data:
        sum1 = (sum1 + character) % 255
        sum2 = (sum1 + sum2) % 255
    return (sum2 << 8) | sum1


if __name__ == "__main__":
    import doctest

    doctest.testmod()