Luhn check digits
Does anyone know an efficient implementation of an algorith to calculate the Luhn check digit of a number? Or know of a library that provides this?
Here's a definition:
Luhn Formula:
1) Double the value of alternate digits beginning with the first right-hand digit (i.e. low order).
2) Add the individual digits comprising the products obtained in step 1 to each unaffected digit in the original number.
3) Subtract the total obtained in step 2 from the next higher multiple of 10. If the total obtained in step 2 is a number ending in zero, the check digit is zero.
Example: The Luhn check digit for 4992739871 is 6, calculated as follows:
1) 418 94 76 916 72
2) 4 + 1 + 8 + 9 + 4 + 7 + 6 + 9 + 1 + 6 + 7 + 2 = 64
3) 70 - 64 = 6
others:
check digit of 111122223333444 is 4
check digit of 1111000000000 is 4
check digit of 1234567890 is 3
check digit of 49927398715 is 0
thanks :)

