开发者

Check digit weighting that will never collide

开发者 https://www.devze.com 2023-03-17 11:06 出处:网络
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 (

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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消