![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
L :
LU :
LUH :
Luhn algorithm |
|
|
Luhn algorithmThe Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm,was developed in the 1960s as a method of validating identification numbers. It is a simple checksum formula used to validate a variety of account numbers, such as credit card numbers and Canadian Social Insurance Numbers. Much of its notoriety comes from credit card companies' adoption of it shortly after its creation in the late 1960s by IBM scientist Hans Peter Luhn (1896–1964). The algorithm is in the public domain and is in wide use today. It is not intended to be a cryptographically secure hash function; it protects against random error, not malicious attack. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from collections of random digits. Informal explanationThe formula generates a check digit, which is usually appended to a partial account number to generate the full account number. This account number must pass the following algorithm (and the check digit chosen and placed so that the full account number will):
AlgorithmThe algorithm proceeds in three steps. Firstly, every second digit, beginning with the next-to-rightmost and proceeding to the left, is doubled. If that result is greater than nine, its digits are summed (which is equivalent, for any number in the range 10 though 18, of subtracting 9 from it). Thus, a 2 becomes 4 and a 7 becomes 5. Secondly, all the digits are summed. Finally, the result is divided by 10. If the remainder is zero, the original number is valid.
function checkLuhn(string purportedCC) { ExampleConsider the example identification number 456-565-654. The first step is to double every other digit, starting with the second-to-last digit and moving left, and sum the digits in the result. The following table shows this step (highlighted rows indicating doubled digits):
The sum of 30 is divided by 10; the remainder is 0, so the number is valid. External link
|
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |