user3752566
user3752566

Reputation: 105

Why Luhn algorithm multiply by 2?

I have question about Luhn algorithm. The luhn algorithm (mod 10) for error detection and check sum digits. For example digits like visa, credit card etc.

for example we have digits : Digits 1 2 3 4 5 6 7 8 9 3

Step 1: Multiply the value of alternate digits by 2, starting from the second rightmost digit. example: Digit 1 2 3 4 5 6 7 8 9 3 Multiplier X2 X2 X2 X2 X2

Step2: Add all the individual digits of the above products together with the un-doubled digits from the original. If more 10 so add or subtract with 9. number.

Example:

Digit       1  2  3  4  5  6  7  8  9  3
Multiplier X2    X2    X2    X2    X2
Result      2  2  6  4 10  6 14  8 18  3
                       1+0   1+4   1+8
Sum         2+ 2+ 6+ 4+ 1+ 6+ 5+ 8+ 9+ 3 = 40

Step 3: If the total modulo 10 is equal to 0, then the number is valid according to the LUHN formula; otherwise it is invalid. example. 40 mod 10 = 0 so valid, if not 0 so not valid.

The question is, why in step 2 using Multiply by 2? what the reason? (with link refrence or papers please). thanks

Upvotes: 3

Views: 659

Answers (1)

Codor
Codor

Reputation: 17605

Although no explicit rationale for this detail is given in the Wikipedia article, the multiplication of every second digit is likely to implement detection of typing errors in which adjacent places are exchanged. More precisely, it is mentioned that

The Luhn algorithm will detect [...] almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence 09 to 90 (or vice versa).

If adjacent places are permutated, the checksum is likely to change. Without the different factors (2 for even positions from the right, 1 for odd positions) this would not be the case.

Upvotes: 3

Related Questions