我把上面的函数精简了一下,就是下面的形式,填入呼号即可算出5位APRS验证码。
callsign : 在这里填入呼号即可
这里面没有错误检查,务必要填写正确哦,bg4myi,必须是这样的形式:大写,中间无空格,调用的时候, int aprsvalidationcode = dohash("bg4myi");
这样即可 :)
int dohash(const char* callsign)
{
int hash = 0x73e2; // initialize with the key value
int i = 0;
int len = strlen(callsign);
char *ptr = callsign;
while (i < len) { // loop through the string two bytes at a time
hash ^= (*ptr++)<<8; // xor high byte with accumulated hash
hash ^= (*ptr++); // xor low byte with accumulated hash
i += 2;
}
return hash & 0x7fff; // mask off the high bit so number is always positive
}