所以我一直试图绕过这个。我有一个用Crockfords base32算法编码的字符串,以及一个基于ISO-7064 Mod 37,36的校验和,需要用PHP解码。
字符串是“66QC”,校验和是“Q”,应该解码为“203500.我已经使用this class来解码字符串,但是在校验和方面我仍然处于亏损状态我似乎无法找到任何关于此的例子并感到迷茫。如果有人做了类似的事情或者能指出正确的方向,我将深表感谢。
答案 0 :(得分:1)
我在VisualBasic中找到了一个工作示例并将其转换为PHP。所以如果有人感兴趣的话:
class ISO7064Decoder
{
public static $iso7064 = array(
'0' => 0,
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
'6' => 6,
'7' => 7,
'8' => 8,
'9' => 9,
'A' => 10,
'B' => 11,
'C' => 12,
'D' => 13,
'E' => 14,
'F' => 15,
'G' => 16,
'H' => 17,
'I' => 18,
'J' => 19,
'K' => 20,
'L' => 21,
'M' => 22,
'N' => 23,
'O' => 24,
'P' => 25,
'Q' => 26,
'R' => 27,
'S' => 28,
'T' => 29,
'U' => 30,
'V' => 31,
'W' => 32,
'X' => 33,
'Y' => 34,
'Z' => 35
);
public static function calculateCheckDigit(String $value)
{
$lngCheck = 36;
$lngLen = strlen($value);
for($lng = 0; $lng <= strlen($value)-1; $lng++)
{
$lngCheck = $lngCheck + self::charToNumber(substr($value, $lng, 1));
if($lngCheck > 36)
{
$lngCheck = $lngCheck - 36;
}
$lngCheck = $lngCheck * 2;
if($lngCheck >= 37)
{
$lngCheck = $lngCheck - 37;
}
}
$lngCheck = 37 - $lngCheck;
if($lngCheck == 36)
{
$lngCheck = 0;
}
return $lngCheck;
}
public static function charToNumber($value)
{
$value = strtoupper($value);
if(!array_key_exists($value, static::$iso7064))
{
return -1;
}
else
{
return static::$iso7064[$value];
}
}
}