Sunday, August 21, 2005

Credit Card Checksums

I came across this while surfing. I knew credit card numbers had checksums in them but never knew exactly how they worked. It's known as the Luhn Algorithm after it's creator Hans Peter Luhn. A simple checksum wouldn't catch swapped adjacent digits, one of the most common errors. So Luhn uses a weighted sum where alternate digits are multiplied by 2 and if that's greater than 10 it's digits are summed. It will detect swapped digits 97.8% and garbled or forged numbers 90% of the time. Simple and elegant.

No comments: