检查永远不会冲突的数字权重
我考虑使用模 10 的数字加权和来实现一个简单的校验位。除了用作校验位之外,我还想“滥用”校验位来检测两个池中的哪一个(例如商品编号和客户编号) ) 一个号码所属。
根据 Wikipedia 建议使用 1、3、7 和 9 作为权重,因此例如,我可以选择:
Article Numbers: Weights 1, 3, 7, 1, 3, 7, ...
Customer Numbers: Weights 7, 9, 1, 7, 9, 1, ...
Number 1234 as an Article Number (1*1+2*3+3*7+4*1 mod 10 = 2): 12342
Number 1234 as a Customer Number (1*7+2*9+3*1+4*7 mod 10 = 6): 12346
问题是,有时这会为两个权重设置提供相同的校验位:
Number 1098 as an Article Number (1*1+0*3+9*7+8*1 mod 10 = 2): 10982
Number 1098 as a Customer Number (1*7+0*9+9*1+8*7 mod 10 = 2): 10982
我是否可以选择数字池的权重,以确保对于任何给定的原始数字,校验位永远不会出现两者都一样泳池?
I thought of implementing a simple check digit using a weighted sum of the digits modulo 10. In addition as serving as a check digit, I want to "abuse" the check digit to detect which of two pools (for example Article Numbers and Customer Numbers) a number belongs to.
According to Wikipedia it is recommended to use 1, 3, 7 and 9 as weight, so for example I could choose:
Article Numbers: Weights 1, 3, 7, 1, 3, 7, ...
Customer Numbers: Weights 7, 9, 1, 7, 9, 1, ...
Number 1234 as an Article Number (1*1+2*3+3*7+4*1 mod 10 = 2): 12342
Number 1234 as a Customer Number (1*7+2*9+3*1+4*7 mod 10 = 6): 12346
The problem is, that sometimes this gives the same check digit for both weight settings:
Number 1098 as an Article Number (1*1+0*3+9*7+8*1 mod 10 = 2): 10982
Number 1098 as a Customer Number (1*7+0*9+9*1+8*7 mod 10 = 2): 10982
Can I choose the weights of the number pools in a way that for any given original number it is ensured that the check digit is never the same for both pools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这是可能的,尽管我必须进行彻底的检查才能确定。
您是否考虑过使用偶数作为商品编号,使用奇数作为客户编号,或者类似的数字?
I doubt it's possible, although I'd have to run an exhaustive check to be sure.
Have you thought about using even numbers for Article Numbers and odd numbers for Customer Numbers, or something like that?