有谁知道以下函数中使用的校验和算法的正式/官方名称?
function Checksum($number, $encode = true)
{
if ($encode === true)
{
$result = 0;
$number = str_split($number, 1);
foreach ($number as $value)
{
$result = ($result + ord($value) - 48) * 10 % 97;
}
return implode('', $number) . sprintf('%02u', (98 - $result * 10 % 97) % 97);
}
else if ($number === Checksum(substr($number, 0, -2), true))
{
return substr($number, 0, -2);
}
return false;
}
function ifMB($entity, $reference, $amount = 0.00)
{
$stack = 923;
$weights = array(62, 45, 53, 15, 50, 5, 49, 34, 81, 76, 27, 90, 9, 30, 3);
$argument = str_split(sprintf('%03u%04u%08u', $entity, $reference, round($amount * 100)), 1);
foreach ($argument as $key => $value)
{
$stack += $value * $weights[$key];
}
return sprintf('%03u%04u%02u', $entity, $reference, 98 - ($stack % 97));
}
谢谢!
答案 0 :(得分:5)
这是ISO7604中描述的纠错码,旨在检测人们在转录数字字符串时所犯的各种常见错误:
该算法主要用于银行帐号验证,但您可以将它用于几乎任何数字字符串。
参考文献: