Friday, May 25, 2007

The Luhn algorithm

Ever wondered how online stores quickly validate that you've typed in your credit card number correctly?

It turns out the credit card number has a built-in checksum, which enables the online store to quickly check whetehr you've made a typo (or just tried to make up a bogus credit card number). The algorithm is called the Luhn agorithm, named after it's inventor who came up with it back in 1950s while at IBM.

The link above has some C# code you can use to check that a number passes the check, or to generate a number that meets the requirements. (You can also put together an Excel spreadsheet quite easily :) )

Of course, this is not meant to be secure - it's meant to detect human errors, not prevent against malicious users.

Now, I wonder how the security number on the back of my credit card is validated?

No comments: