Luhn Algorithm, named after IBM scientist Hans Peter Luhn (1896-1964), who was awarded US Patent 2950048 ("Computer for Verifying Numbers") for the technique in 1960. For details about Luhn's life, see:
- Biography on the American Society for Information Science and Technology's Web site
- Notes compiled by Susan K. Soy on "H.P. Luhn and Automatic Indexing
The most succinct description of the Luhn algorithm I have found comes from the hacker publication phrack 47-8: "For a card with an even number of digits, double every odd numbered digit and subtract 9 if the product is greater than 9. Add up all the even digits as well as the doubled-odd digits, and the result must be a multiple of 10 or it's not a valid card. If the card has an odd number of digits, perform the same addition doubling the even numbered digits instead."
The bit about even and odd is a little confusing. The main point is that you don't want to double the check digit, and this can easily be done by starting with the check digit, going backwards, and doubling every other digit. See the source code below for details.