Sunday, March 9, 2008

Numbers....we got to deal with!

This is the third time in last couple of years....and, it happened again.
Its my good old Visa credit card, and the "surprise dollars" which gets charged once in a while --numbers are small and very deceiving!! I don't know where the mystery charges appear from, once it said " from Russia" -- for 11.99 dollars-- Russian sites...Hmm... and then couple of years back, it was a "fish company" from Alabama for 38.69... "mama's shack" in New Orleans for 29.99.

I am sure some of us have gone through this experience...which is not quite so fun, Trick is to catch them early.. Well, Security aspect apart, which is a topic in itself, other interesting thing that caught my attention is the 16 number on the credit card, Do we know how they generate it, Is there a rule they follow?

This blog is specifically targeted to understand the magic behind the long numbers we see on our card. Hey, I got to warn you... there is some serious "math" involved, so, have fun!!

Typical credit card anatomy

Before we understand how credit card numbers are generated, here is a brief explanation of what a typical credit card number means.

  • Out of the 16 numbers on a typical credit card, the set of first 6 digits is known as the issuer identifier number, and the last digit is known as the “check digit” which is generated in such a way as to satisfy a certain condition (the Luhn or Mod 10 check). “Luhn check” is explained later in this post. The term sounds intimidating, but it’s really a very simple (and elegant) concept.
  • Taking away the 6 identifier digits and 1 check digit leaves us with 9 digits in the middle that form the “account number”.
  • Now, there are 10 possible numbers (from 0 to 9) that can be arranged in these 9 places.

Different Card Samples

What is the “Luhn” or “Mod 10″ check?

In 1954, Luhn of IBM proposed an algorithm to be used as a validity criterion for a given set of numbers. Almost all credit card numbers are generated following this validity criterion…

  1. Starting with the check digit, double the value of every second digit (never double the check digit). For example, in a 16 digit credit card number, double the 15th, 13th, 11th, 9th…digits (digits in odd places). In all, you will need to double eight digits.
  2. If doubling of a number results in a two digit number, add up the digits to get a single digit number. This will result in eight single digit numbers.
  3. Now, replace the digits in the odd places (in the original credit card number) with these new single digit numbers to get a new 16 digit number.
  4. Add up all the digits in this new number. If the final total is perfectly divisible by 10, then the credit card number is valid (Luhn check is satisfied), else it is invalid.

This part is a bit confusing and takes some time to understand. However, don’t get stuck here…continue reading through the examples below and you will figure out what this is all about.

Credit card numbers valid or invalid?

Have you ever wondered if those numbers on the fake plastic or cardboard credit cards that come with the “preapproved” offers are real or imaginary? If they are not valid, how do you know it?…Just apply the Luhn check and all the those fake credit cards will invariably fail.Here is an example of a VISA credit card (look at the expiry date - 01/09’s still valid !

Note that the credit card number starts with “4″…so it is indeed a VISA issued credit card (VISA cards start with “4″ and MasterCard/Maestro cards start with “5″). Now, let us apply the Luhn algorithm to this card.

  • In this case, when we sum up the total, it comes to 61 which is not perfectly divisible by 10, and hence this credit card number is invalid.
  • If such a credit card number is ever generated, the value of the check digit would be adjusted in such a way as to satisfy the Luhn condition. In this case, the only value of the check digit, that will create a valid credit card number, is 7. Choosing 7 as the check digit will bring the total to 60 (which is perfectly divisible by 10) and the Luhn condition will be satisfied. So the valid credit card number will be 4552 7204 1234 5677.

    Closing remarks

    The Luhn formula validates only the credit card number; it does not validate the expiry date and/or card security code (CVV, CVC). Plus, as discussed before, the 9 digit account number will yield 1 billion combinations; so the chances of getting a working credit card number are very remote. It should also be noted that, this validation is usually employed at the transaction end; which means that numbers that do not satisfy the Luhn check are not forwarded to the card issuer and the transaction is terminated. If you have a fake credit card which satisfies the Luhn check, it will go through at the transaction end, but the card issuer will most likely catch the mischief. So don’t go about trying to use these numbers to buy stuff.

2 comments: said...

Rakesh, Please don't blame someone else for the unaccounted expenses which your wife has identified in your credit card bill! :P

Anonymous said...

good comment.