首页 » 业余 » Ham Radio » 正文

javascript 版 ᴀᴘʀs 验证码计算

发布者:站点默认
2021/03/29 浏览数(599) 分类:Ham Radio, Javascript javascript 版 ᴀᴘʀs 验证码计算已关闭评论
function dodash(callsign = '') {
  var sign = callsign.match(/[a-z0-9]+/)[0].toUpperCase();
  var hash = 0x73e2;
  var i = 0;
  while (i < sign.length) {
    var f = sign[i].charCodeAt();
    hash ^= f<<8;
    if (sign[i + 1]) {
        var s = sign[i+1].charCodeAt();
        hash ^= s;
    }
    i += 2;
  }
  return Math.abs(hash);
}

var code = dodash('BZ0ZZZ');
console.log(code);

demo

#define kkey 0x73e2            // this is the key for the data
short dohash(const char* thecall)
{
  char rootcall[10];     // need to copy call to remove ssid from parse
  char *p1 = rootcall;

  while ((*thecall != '-') && (*thecall != 0)) *p1++ = toupper(*thecall++);
    *p1 = 0;

  short hash = kkey;     // initialize with the key value
  short i = 0;
  short len = strlen(rootcall);
  char *ptr = rootcall;
 
  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
}
点击返回顶部
  1. 留言
  2. 联系方式