检查永远不会冲突的数字权重

发布于 2024-11-18 19:43:34 字数 731 浏览 2 评论 0原文

我考虑使用模 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心小果奶 2024-11-25 19:43:34

我怀疑这是可能的,尽管我必须进行彻底的检查才能确定。

您是否考虑过使用偶数作为商品编号,使用奇数作为客户编号,或者类似的数字?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文