由呼号生成APRS系统密码的程序
原来的开源项目在这里,是PHP的,http://apps.magicbug.co.uk/passcode/index.php
翻了一下代码,php的生成密码的核心代码是这样子的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php
function aprspass ($callsign) { $stophere = strpos($callsign, '-'); if ($stophere) $callsign = substr($callsign, 0, $stophere);
$realcall = strtoupper(substr($callsign, 0, 10)); $hash = 0x73e2; $i = 0; $len = strlen($realcall); while ($i < $len) { $hash ^= ord(substr($realcall, $i, 1))<<8; $hash ^= ord(substr($realcall, $i + 1, 1)); print('hash:'. $i . ' ' . $hash); $i += 2; } return $hash & 0x7fff; }
print(aprspass('BH4FWA-1'));
|
大概的原理是,将原本的 输入的呼号内容,将 - 去掉,取前面一部分,然后再将其遍历,偶数位的 拿到 ascii码,左移8,奇数位的不变,并且与一个base bash不断异或,
最终返回 pass-code。
预览: