EXAMPLE 3 Luhn Algorithm Check Digit

To demonstrate how to calculate a check digit using the Luhn algorithm, suppose a bank intends to issue a credit card with the identification number 312560019643001. We calculate to get 66. Then we note that among the digits in the odd-numbered positions, only 6 and 9 are greater than or equal to 5. So we add 2 to 66 to get 68. The check digit is whatever is needed to bring the final tally to a number that ends with 0. Because , the check digit for our example is 2. This digit is appended to the end of the number the bank issues for identification purposes. Errors in input data are detected by applying the same algorithm to the input, including the check digit. If the correct number is entered into a computer, the result will end in 0. If the result doesn't end with 0, a mistake has been detected.