//转化成十六进制, 调用的是vbscript的Hex函数
function Hex(n)
{
c = n;
execScript("c = Hex(c)", "vbscript");
return c;
}
//返回文字的AscaII编码, 调用的是vbscript的Asc函数
function Asc(s)
{
c = s;
execScript("c = Asc(c)", "vbscript");
return c;
}
//获取文字的gb2312编码
function gb2312Encode(str)
{
var string = "";
c = s = "";
var high = "";
var low = "";
for(var i = 0; i < str.length; i++)
{
c = Asc(str.charAt(i));
if(Math.abs(c) < 0xFF)
string += str.charAt(i);
else
{
if(c < 0) c += 0x10000;
high = ((c & 0xFF00) >> 8) & 0x00FF;
low = c & 0xFF;
string += "%" + Hex(high) + "%" + Hex(low);
}
}
return string;
}
//将收到的gb2312编码进行解码
function gb2312Decode(data)
{
string = "";
str = "";
d = data;
n = "";
c = "";
execScript("l = LenB(d)", "vbscript");
execScript("d = MidB(d, 1)", "vbscript");
for( i = 1; i <= l; i++)
{
execScript("c = AscB(MidB(d, i, 1))", "vbscript");
if( c < 0x80)
{
execScript("str = Chr(c)", "vbscript");
string += str;
}
else
{
execScript("n = AscB(MidB(d, i + 1, 1))", "vbscript");
execScript("str = Chr(CLng(c) * &H100 + CInt(n))", "vbscript");
string += str;
i = i + 1;
}
}
return string;
}