Tuesday, February 18, 2014

Credit Card Numbers - In-depth analysis

Every day everyone uses a credit card to pay for many different things out there. Whether it be your normal bills, or going out to eat, but how do they work?
  • How do websites know my credit card is valid? 
  • Do they have these numbers stored or do they pole credit card providers for the information? 
These are some of the questions we will be going over today.

A good resource, even though it is Wikipedia, is: http://en.wikipedia.org/wiki/Bank_card_number

The first 6 digits help you identify the vendor of the credit card number. Depending on the vendor, it may only be up to 4.


The first digit of a credit card number is the Major Industry Identifier (MII). MII digits represent the following issuer categories:
  • 0 – ISO/TC 68 and other future industry assignments
  • 1 – Airlines
  • 2 – Airlines and other future industry assignments
  • 3 – Travel and entertainment and banking/finance
  • 4 – Banking and finance
  • 5 – Banking and finance
  • 6 – Merchandising and banking/finance
  • 7 – Petroleum and other future industry assignments
  • 8 – Healthcare, telecommunications and other future industry assignments
  • 9 – National assignment
So now we have the first few digits identified. What do the other numbers mean?

In the old days, if you typed in your credit card number and purchased something online or provided your card over the phone, the manufacture would take up to a week to tell you the credit card number is wrong.

Now-a-days they can use an algorithm to validate the credit card number and tell you right away, before you even submit your card, that it is invalid. The algorithm is called the Luhn algorithm. This is the basic concept of how it works:
  1. From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9, then sum the digits of the products.
  2. Take the sum of all the digits.
  3. If the total modulo 10 is equal to 0 (if the total ends in a zero) then the number is valid according to the Luhn formula; else it is not valid.
After you complete the math provided above on the given credit card number, the last digit is what you should come up with. If the digit does not match what you got, it's an invalid credit card. If it does, it's valid.

Since we like to focus on C#, I will post a C# implementation of the Luhn algorithm at a later time.

No comments: