trinity notes   Luhn Formula

Thinking!

 

Supported by Enterprise IrelandThe PDC

The LUHN formula

The 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. 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 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.

The first part of the credit-card number identifies the type of credit card (Visa, MasterCard, American Express, etc.), and the middle digits identify the bank and customer.

Card Type

Prefix

Length

MASTERCARD

51-55

16

VISA

4

13,16

AMEX

34, 37

15

Diners Club

300-305, 36,38

14

Discover

6011

16

 

To generate the check digit, the LUHN formula is applied to the number. To validate the credit-card number, the check digit is figured into the formula. Here's how the algorithm works for verifying credit cards; the math is quite simple:

  1. Starting with the second last digit and moving left, double the value of all the alternating digits.
  1. Starting from the left, take all the unaffected digits and add them to the results of all the individual digits from step 1. If the results from any of the numbers from step 1 are double digits, make sure to add the two numbers first (i.e. 18 would yield 1+8). Basically, your equation will look like a regular addition problem that adds every single digit.
  1. The total from step 2 must end in zero for the credit-card number to be valid.

 

Credit Card Number:      

5

4

4

3

2

3

8

1

4

5

4

3

1

3

8

3

x2

 

x2

 

x2

 

X2

 

x2

 

x2

 

x2

 

x2

 

10

4

8

3

4

3

16

1

8

5

8

3

2

3

16

3

(1+0)

4

8

3

4

3

(1+6)

1

8

5

8

3

2

3

(1+6)

3

1

4

8

3

4

3

7

1

8

5

8

3

2

3

7

3

Grand Total: 70

If when we divide the grand total by ten the remainder is 0 the algorithm validates and we can assume that the credit card details have been entered correctly. This does not mean

Of course this does not mean that the credit card has been issued by a valid company or that this account has sufficient funds to cover the sale. It is only meant to protect against random error rather than malicious attack.

Download the Luhn Formula Excel Demo.

 

Back

     
Home | Legal | Privacy | Site Map Copyright © 2005 Mopanisoft. All Rights Reserved.