How to validate credit-card numbers

by Fredrik Savin on 20/09/2007 · 0 comments

I came across an interesting article in the Economist recently about the use of mathematical algorithms in business. An algorithm is essentially a procedure or formula for solving a problem. The speed and processing power of today’s computers mean that algorithms can execute tasks and solve problems at an incredible speed. Examples of algorithms used in business include the ones used by search-engine companies such as Google.

The Economist explains in their article how one can validate credit-card numbers using an algorithm called the Luhn algorithm. The algorithm, which was created by an IBM researcher more than 40 years ago, can be used to validate the numbers entered by consumers on an e-commerce site, for example, to keep processing times down.

Example (from the Economist):

Step 1: Take the original credit card number:
3 7 7 9 5 6 5 7 0 9 4 4 7 2 6
Step 2: Reverse the numbers
6 2 7 4 4 9 0 7 5 6 5 9 7 7 3
Step 3: Double every second number
4 8 18 14 12 18 14
Step 4: Add the numbers up (if more than nine, subtract nine)
6 4 7 8 4 9 0 5 5 3 5 9 7 5 3

The answer is 80. The credit card number is valid if divisible by 10.

The Luhn algorithm can be used in a number of programming languages such as C#, Java and PHP. More information and examples on how to use the algorithm can be found below:

http://en.wikipedia.org/wiki/Luhn_algorithm

Reference:

The Economist, “Business by numbers”, p. 81, September 15th 2007

Leave a Comment

Additional comments powered by BackType

Previous post:

Next post: