algorithm - 基于 Damm 校验位的纠错
问题描述
如果您使用Damm 算法生成校验位,如果代码未验证,是否有尝试纠正错误的方法?
解决方案
不,该算法只能用于检测错误,不能纠正错误。
这可以用一个简单的例子来证明。假设您收到一个包含数字的数字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
数字以获得正确的校验和。
推荐阅读
- reactjs - React.js 中每个项目的计数器
- blazor - C# Blazor onParametersSetAsync 被调用,尽管 params 没有改变
- bash - 使用 sed 以编程方式创建正则表达式以在 gawk 中使用
- r - 在 R 中使用 varimax 旋转后,如何使用 factoextra 创建双图?
- python - 灰度图像上的颜色轮廓
- oracle-apex - 从 Oracle Apex 应用程序后端表获取 Power BI 中的数据
- powershell - Powershell Select-Object 计算属性数据类型
- paypal - vbscript xmlhttp 完成客户端认证需要证书
- java - Java/Kotlin 中时区的操作逻辑是什么?
- r - r - 查找所有组合,不包括来自同一组的组合