MsgBox(0,"",base64('cn=测 试,ou=gsphonebook,dc=sz,dc=com'))
Func base64($str,$p=1)
Local $code
$code&='var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";'&@CRLF
$code&='var base64DecodeChars = new Array('&@CRLF
$code&='-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,'&@CRLF
$code&='-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,'&@CRLF
$code&='-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,'&@CRLF
$code&='52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,'&@CRLF
$code&='-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,'&@CRLF
$code&='15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,'&@CRLF
$code&='-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,'&@CRLF
$code&='41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);'&@CRLF
$code&='function base64encode(str) {'&@CRLF
$code&='var out, i, len;'&@CRLF
$code&='var c1, c2, c3;'&@CRLF
$code&='len = str.length;'&@CRLF
$code&='i = 0;'&@CRLF
$code&='out = "";'&@CRLF
$code&='while(i < len) {'&@CRLF
$code&='c1 = str.charCodeAt(i++) & 0xff;'&@CRLF
$code&='if(i == len)'&@CRLF
$code&='{'&@CRLF
$code&='out += base64EncodeChars.charAt(c1 >> 2);'&@CRLF
$code&='out += base64EncodeChars.charAt((c1 & 0x3) << 4);'&@CRLF
$code&='out += "==";'&@CRLF
$code&='break;'&@CRLF
$code&='}'&@CRLF
$code&='c2 = str.charCodeAt(i++);'&@CRLF
$code&='if(i == len)'&@CRLF
$code&='{'&@CRLF
$code&='out += base64EncodeChars.charAt(c1 >> 2);'&@CRLF
$code&='out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));'&@CRLF
$code&='out += base64EncodeChars.charAt((c2 & 0xF) << 2);'&@CRLF
$code&='out += "=";'&@CRLF
$code&='break;'&@CRLF
$code&='}'&@CRLF
$code&='c3 = str.charCodeAt(i++);'&@CRLF
$code&='out += base64EncodeChars.charAt(c1 >> 2);'&@CRLF
$code&='out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));'&@CRLF
$code&='out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));'&@CRLF
$code&='out += base64EncodeChars.charAt(c3 & 0x3F);'&@CRLF
$code&='}'&@CRLF
$code&='return out;'&@CRLF
$code&='}'&@CRLF
$code&='function base64decode(str) {'&@CRLF
$code&='var c1, c2, c3, c4;'&@CRLF
$code&='var i, len, out;'&@CRLF
$code&='len = str.length;'&@CRLF
$code&='i = 0;'&@CRLF
$code&='out = "";'&@CRLF
$code&='while(i < len) {'&@CRLF
$code&='do {'&@CRLF
$code&='c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];'&@CRLF
$code&='} while(i < len && c1 == -1);'&@CRLF
$code&='if(c1 == -1)'&@CRLF
$code&='break;'&@CRLF
$code&='do {'&@CRLF
$code&='c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];'&@CRLF
$code&='} while(i < len && c2 == -1);'&@CRLF
$code&='if(c2 == -1)'&@CRLF
$code&='break;'&@CRLF
$code&='out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));'&@CRLF
$code&='do {'&@CRLF
$code&='c3 = str.charCodeAt(i++) & 0xff;'&@CRLF
$code&='if(c3 == 61)'&@CRLF
$code&='return out;'&@CRLF
$code&='c3 = base64DecodeChars[c3];'&@CRLF
$code&='} while(i < len && c3 == -1);'&@CRLF
$code&='if(c3 == -1)'&@CRLF
$code&='break;'&@CRLF
$code&='out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));'&@CRLF
$code&='do {'&@CRLF
$code&='c4 = str.charCodeAt(i++) & 0xff;'&@CRLF
$code&='if(c4 == 61)'&@CRLF
$code&='return out;'&@CRLF
$code&='c4 = base64DecodeChars[c4];'&@CRLF
$code&='} while(i < len && c4 == -1);'&@CRLF
$code&='if(c4 == -1)'&@CRLF
$code&='break;'&@CRLF
$code&='out += String.fromCharCode(((c3 & 0x03) << 6) | c4);'&@CRLF
$code&='}'&@CRLF
$code&='return out;'&@CRLF
$code&='}'&@CRLF
$code&='function utf16to8(str) {'&@CRLF
$code&='var out, i, len, c;'&@CRLF
$code&='out = "";'&@CRLF
$code&='len = str.length;'&@CRLF
$code&='for(i = 0; i < len; i++) {'&@CRLF
$code&='c = str.charCodeAt(i);'&@CRLF
$code&='if ((c >= 0x0001) && (c <= 0x007F)) {'&@CRLF
$code&='out += str.charAt(i);'&@CRLF
$code&='} else if (c > 0x07FF) {'&@CRLF
$code&='out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));'&@CRLF
$code&='out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));'&@CRLF
$code&='out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));'&@CRLF
$code&='} else {'&@CRLF
$code&='out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));'&@CRLF
$code&='out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));'&@CRLF
$code&='}'&@CRLF
$code&='}'&@CRLF
$code&='return out;'&@CRLF
$code&='}'&@CRLF
$code&='function utf8to16(str) {'&@CRLF
$code&='var out, i, len, c;'&@CRLF
$code&='var char2, char3;'&@CRLF
$code&='out = "";'&@CRLF
$code&='len = str.length;'&@CRLF
$code&='i = 0;'&@CRLF
$code&='while(i < len) {'&@CRLF
$code&='c = str.charCodeAt(i++);'&@CRLF
$code&='switch(c >> 4)'&@CRLF
$code&='{'&@CRLF
$code&='case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:'&@CRLF
$code&='out += str.charAt(i-1);'&@CRLF
$code&='break;'&@CRLF
$code&='case 12: case 13:'&@CRLF
$code&='char2 = str.charCodeAt(i++);'&@CRLF
$code&='out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));'&@CRLF
$code&='break;'&@CRLF
$code&='case 14:'&@CRLF
$code&='char2 = str.charCodeAt(i++);'&@CRLF
$code&='char3 = str.charCodeAt(i++);'&@CRLF
$code&='out += String.fromCharCode(((c & 0x0F) << 12) |'&@CRLF
$code&='((char2 & 0x3F) << 6) |'&@CRLF
$code&='((char3 & 0x3F) << 0));'&@CRLF
$code&='break;'&@CRLF
$code&='}'&@CRLF
$code&='}'&@CRLF
$code&='return out;'&@CRLF
$code&='}'&@CRLF
$VBS = ObjCreate("ScriptControl")
$VBS.language = "jscript"
$VBS.addcode($code)
If $p=1 Then
Return $VBS.Eval("base64encode(utf16to8('"&$str&"'))")
ElseIf $p=0 Then
Return $VBS.Eval("utf8to16(base64decode('"&$str&"'))")
EndIf
EndFunc
其实做一下编码转换就好了,懒得写。直接调用js吧 |