Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Luhn or Verhoeff algorithm for credit card numbers

First of all, I'm not really sure if this should be on stackoverflow but I thought I would try to ask anyway.

In the past I have always used the luhn algorithm for error checking in credit card numbers, but today I thought I would implement the verhoeff algorithm in php, mainly to kill time.

I tested it out on my own card numbers and it worked fine, which started me thinking about whether I should use verhoeff over luhn for my credit card number error checking in the future.

Now my questions:

Would there be any significant advantage in using verhoeff over luhn?

I know that verhoeff is slightly more complex in it's implementation and it can detect more transcription errors than luhn, which would naturally lead me to believe it's a bit slower, but aside from the advantage of detecting more transcription errors and the dis-advantage (if you can really call it that) of being slightly slower, I can't think of any other real differences.

Will the verhoeff algorithm work for all major cards?

I know that luhn will work for all of the major cards but will verhoeff also work for all of them? I am under the assumption that it will work for all of them but I thought I should check anyway.

Is there a reason that I have only seen people using luhn to check credit card numbers?

In all of my time as a developer I have only really seen people using the luhn algorithm to check credit card numbers. Is there a good reason for this, or is it simply that luhn is more well known?

Any help would be appreciated, thank you for you time.

like image 378
Lucas Avatar asked Nov 24 '11 11:11

Lucas


1 Answers

They are different algorithms and can give different results (if the results were always the same then they would be equal in power - you already said that Verhoeff was stronger, so you must agree that there are some numbers that give different values to Luhn!).

When used with a credit card you check the final digit against the rest of the number. This check digit is present on the card (so is fixed) and is calculated using the Luhn algorithm.

So you cannot use Verhoeff, because the final digit on a credit card is for Luhn. To use Verhoeff instead you would have to change the final digit of (some of) the cards that already exist.

The people who designed the original credit card format had this choice (modulo historical details) and decided to go with Luhn. They chose. You cannot alter their decision in retrospect because the Luhn check digit is present on existing cards.

(I have no idea how you managed to check your cards with this algorithm. Ether you were lucky, or your code is broken, or I am wrong...)

In simple terms: it will not work. They are not the same and the choice of Luhn was made by the credit card issuer.

In more complex terms: if the two were compatible then they would be equal in power and there would be no point in switching. You cannot have two checksums of different power that give identical results. It's a subtle point, but think it over...

like image 146
andrew cooke Avatar answered Dec 11 '22 02:12

andrew cooke