[实用程序源码及工具软件] HotCRC内的HexToUUEncode()源码

[复制链接]
 楼主| hotpower 发表于 2023-9-23 10:10 | 显示全部楼层 |阅读模式
菜农电子淘宝:https://hotcomlock.taobao.com/ 准备出书:http://hotcomlock.com/hotcomlock.html

  1.     function HexToUUEncode(hexstr)
  2.     {
  3.         var i, str, hexstrString;
  4.         hexstrString = "";
  5.         for (i = 0; i < hexstr.length; i += 8)
  6.         {
  7.             hexstrString += HexStrToUUEncode(hexstr.substr(i, 8));
  8.         }
  9.         return hexstrString;//输出3N个字节
  10.     }
  1.     function GetUUEncodeValue(ch)
  2.     {
  3.         var value = 0;
  4.         if((ch >= " ") && (ch <= "_")) {
  5.             value = ch.charCodeAt(0) - 0x20;
  6.         }
  7.         return value;
  8.     }
  1.     function HexStrToUUEncode(basehexstr)
  2.     {//输入4个字节
  3.         var c, a, t, x1, x2, x3, x4, str, hexstr;
  4.         str = HexToAscii(basehexstr);//4个字符
  5.         x1 = GetUUEncodeValue(str.substr(0, 1));
  6.         x2 = GetUUEncodeValue(str.substr(1, 1));
  7.         x3 = GetUUEncodeValue(str.substr(2, 1));
  8.         x4 = GetUUEncodeValue(str.substr(3, 1));
  9.         hexstr = "";
  10.         if(str.substr(3, 1) != "`") {
  11.             c = (x1 << 2) | (x2 >>> 4);
  12.             a = ((x2 & 0xf) << 4) | (x3 >>> 2);
  13.             t = ((x3 & 0x03) << 6) | x4;
  14.             hexstr = inttohex(c, 2);
  15.             hexstr += inttohex(a, 2);
  16.             hexstr += inttohex(t, 2);
  17.         }
  18.         else if(str.substr(2, 1) != "`") {
  19.             c = (x1 << 2) | (x2 >>> 4);
  20.             a = ((x2 & 0xf) << 4) | (x3 >>> 2);
  21.             hexstr = inttohex(c, 2);
  22.             hexstr += inttohex(a, 2);
  23.         }
  24.         else {
  25.             c = (x1 << 2) | (x2 >>> 4);
  26.             hexstr = inttohex(c, 2);
  27.         }
  28.         return hexstr;//输出3个字节
  29.     }


您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

508

粉丝
快速回复 在线客服 返回列表 返回顶部