使用什么算法来计算校验位?
使用什么算法来计算数字列表的校验位?
列表的长度在 8 到 12 位数字之间。
另请参阅:
如何生成验证码/号码?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Luhn 算法 对于信用卡行业来说已经足够好了......
The Luhn algorithm is good enough for the credit card industry...
正如 RichieHindle 指出的那样,Luhn 算法非常好。 它将检测(但不纠正)任何一个错误或换位(0 和 9 的换位除外)。
您还可以考虑 ISBN 校验位 的算法,尽管对于旧式 ISBN,校验位有时是“X”,如果您使用整数字段,这可能会给您带来问题。 新式ISBN似乎不存在这个问题。 维基百科没有讨论系统的理论属性,但我记得很久以前在我的编码理论课程中研究过 ISBN 数字,所以我认为它们非常好:-)
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 :-)
我知道有点晚了(根据发布日期),但我第一次需要支票号码算法是在上周。
所以我检查了更多算法,恕我直言,最好的解决方案似乎是 Damm 算法。
它易于实施并检测大多数测试错误。 使用默认的数字检查表,所有单位数字错误、所有英语听错错误、所有相邻换位错误和几乎所有跳跃换位错误都是可检测的。
对我来说只有一个问题,因为我不仅需要根据数字计算校验位,还需要根据字符计算校验位。 对我来说不幸的是,有一个给定的规则,最后一个字符必须是数字; 或者更好地说,这些字符是由第三方机构分配的,并且仅使用固定数量的数字作为制造商编号。
将字符转录为数字的方法有很多种,但与仅使用数字时相比,错误检测总是较低。
对于这些情况,您可以使用 ISO_6346 规范。
当没有这样的限制时,使用不同大小的表格,并将字符和数字分配给表格值。
编辑:更新/修复了描述,添加了字符数字检查编号的原因,并添加了不同基本尺寸的表格。
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 seems to be the Damm algorithm.
It is simple to implementation and detect most of tested errors. With default digit check table all single digit errors, all English language mishearing errors, all adjacent transposition errors, and almost all jump transpositions errors are detectable.
For me there was only a single problem, since I need to calculate check digit not only from numbers but also from characters. Unfortunately for me, there was a given rule, that the last character must be a digit; or better to say, the characters were assigned by third party authority and only fixed amount of numbers were used as manufacturer number.
There are many ways how to transcribe characters to number, but the error detection will always be lower, comparing to when only numbers are used.
For these cases you can use the ISO_6346 specification.
When there is no such limitation, use the tables for different size and assign characters and number to table values.
EDIT: updated/fixed description, added reason for digit check number for characters, and added tables for different base sizes.
Luhn 算法
校验数字算法
校验数字算法导师
ISIN校验位算法
Luhn algorithm
Check Digit Algorithm
Check Digit Algorithms Tutor
ISIN check digit algorithm
Verhoeff,我认为没有比这更好的了。
Verhoeff, there is nothing better IMO.