What algorithm to use to calculate a check digit?

。_饼干妹妹 提交于 2019-12-05 23:42:28

问题


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?


回答1:


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




回答2:


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 :-)




回答3:


Luhn algorithm

Check Digit Algorithm

Check Digit Algorithms Tutor

ISIN check digit algorithm




回答4:


Verhoeff, there is nothing better IMO.




回答5:


I know it is a bit late (according to post dates), but first time I needed a check number algorithm was last week.

So I checked more algorithms and IMHO the best solution (for only digits) seems to be the Damm algorithm. It is simple to implementation and detect most of tested errors (all single digit errors and all transposition errors, almost all jump transpositions errors).

For me there was only a single problem, since I need to calculate check digit not only from numbers but also from characters. There are many ways how to transcribe characters to number, but the error detection will always be lower than only numbers are used.

For these cases you can use the ISO_6346 specification.



来源:https://stackoverflow.com/questions/1100730/what-algorithm-to-use-to-calculate-a-check-digit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!