views:

566

answers:

5

What algorithm to use to calculate a check digit for a list of digits?
The length of the list is between 8 and 12 digits.

see also:
How to generate a verification code/number?

+7  A: 

The Luhn algorithm is good enough for the credit card industry...

RichieHindle
Luhn algorithm is way to weak, try swapping the first digit with the last digit - ooops, valid!
Alix Axel
+5  A: 

As RichieHindle points out, the Luhn algorithm is pretty good. It will detect (but not correct) any one error or transposition (except a transposition of 0 and 9).

You could also consider the algorithm for ISBN check digits, although for old-style ISBN, the check digit is sometimes "X", which may be a problem for you if you're using integer fields. New-style ISBN doesn't seem to have that problem. Wikipedia doesn't go in to the theoretical properties of the system, but I remember studying ISBN numbers in my coding theory course long ago, so I think they are pretty good :-)

John Fouhy
+1 for the ISBN check digit. That brought me back memories...
Stefano Borini
A: 

And the range of the integers is?

Paddy3118
Can you clarify?
Piotr Dobrogost
-1 Shouldn't this be a comment?
Alix Axel
+1  A: 

Verhoeff, there is nothing better IMO.

Alix Axel