首页 > 解决方案 > 基于 Damm 校验位的纠错

问题描述

如果您使用Damm 算法生成校验位,如果代码未验证,是否有尝试纠正错误的方法?

标签: algorithmerror-correctioncheck-digit

解决方案


不,该算法只能用于检测错误,不能纠正错误。

这可以用一个简单的例子来证明。假设您收到一个包含数字的数字9857。当您对该数字运行算法时,结果为 6。因此其中一位数字已更改。但是哪一个?

通过蛮力搜索,您可以确定原始数字可能是以下任何一个:

original                                                resulting
 number             error that occurred                  number
  1857      the first  digit got changed from 1 to 9      9857
  9157      the second digit got changed from 1 to 8      9857
  9827      the third  digit got changed from 2 to 5      9857
  9850      the fourth digit got changed from 0 to 7      9857

因此,包含错误的数字不能唯一标识原始数字。

一般来说,可以通过更改任何一位数字来获得正确的校验和。也就是说,如果你收到一个带N数字的数字,并且校验和不为 0,则可以更改任何一个N数字以获得正确的校验和。


推荐阅读