One method that is used by some simple protocols is a modulo sum. The ASCII bytes that come across the wire are treated as unsigned 8-bit binary numbers and added into an ongoing sum. Any carry is thrown away, which is identical to taking the 256 modulus of the sum. In fact, this may have been the origin of the term checksum, which combines the purpose (to check for errors) with the method (summing the bytes). A variation of this method used by the TCP protocol is to use the XOR function instead of full binary addition, since XOR is faster. Checksumming by simple addition or XORing suffers from several weaknesses in that it can fail to detect some kinds of errors. For example, swapping the order of the bytes has no effect on the checksum, since addition and XOR is commutative. Mathematicians study all the various techniques and chart the characteristics of each method, such as how bit errors can it detect, how many can it correct, and how far apart error bits can be in a burst error before the method will break down. |