HotCRC内的HexToUUEncode()源码
菜农电子淘宝:https://hotcomlock.taobao.com/ 准备出书:http://hotcomlock.com/hotcomlock.htmlfunction HexToUUEncode(hexstr)
{
var i, str, hexstrString;
hexstrString = "";
for (i = 0; i < hexstr.length; i += 8)
{
hexstrString += HexStrToUUEncode(hexstr.substr(i, 8));
}
return hexstrString;//输出3N个字节
}
function GetUUEncodeValue(ch)
{
var value = 0;
if((ch >= " ") && (ch <= "_")) {
value = ch.charCodeAt(0) - 0x20;
}
return value;
}
function HexStrToUUEncode(basehexstr)
{//输入4个字节
var c, a, t, x1, x2, x3, x4, str, hexstr;
str = HexToAscii(basehexstr);//4个字符
x1 = GetUUEncodeValue(str.substr(0, 1));
x2 = GetUUEncodeValue(str.substr(1, 1));
x3 = GetUUEncodeValue(str.substr(2, 1));
x4 = GetUUEncodeValue(str.substr(3, 1));
hexstr = "";
if(str.substr(3, 1) != "`") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
t = ((x3 & 0x03) << 6) | x4;
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
hexstr += inttohex(t, 2);
}
else if(str.substr(2, 1) != "`") {
c = (x1 << 2) | (x2 >>> 4);
a = ((x2 & 0xf) << 4) | (x3 >>> 2);
hexstr = inttohex(c, 2);
hexstr += inttohex(a, 2);
}
else {
c = (x1 << 2) | (x2 >>> 4);
hexstr = inttohex(c, 2);
}
return hexstr;//输出3个字节
}
https://bbs.21ic.com/data/attachment/forum/202309/22/101124qp474qggq7ix7pjx.jpg.thumb.jpg
页:
[1]