function Base64Encode (str) { var out,i,len,base64encodechars= "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"; var c1,c2,c3; Len=str.length; i=0; Out= ""; while (I<len) { C1=str.charcodeat (i++) &0xff; if (I==len) { Out+=base64encodechars.charat (C1>>2); Out+=base64encodechars.charat ((c1&0x3) <<4); out+= "= ="; Break } C2=str.charcodeat (i++); if (I==len) { Out+=base64encodechars.charat (C1>>2); Out+=base64encodechars.charat ((c1&0x3) <<4) | ( (c2&0xf0) >>4)); Out+=base64encodechars.charat ((C2&0XF) <<2); out+= "="; Break } C3=str.charcodeat (i++); Out+=base64encodechars.charat (C1>>2); Out+=base64encodechars.charat ((c1&0x3) <<4) | ( (c2&0xf0) >>4)); Out+=base64encodechars.charat ((c2&0xf) <<2) | ( (C3&0XC0) >>6)); Out+=base64encodechars.charat (c3&0x3f); } return out; } function Base64decode (str) { var c1,c2,c3,c4,base64decodechars=new Array ( -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 , -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,- 1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,- 1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1); var i,len,out; Len=str.length; i=0; Out= ""; while (I<len) { * C1 * * do{ C1=base64decodechars[str.charcodeat (i++) &0xff]; }while (I<len&&c1==-1); if (c1==-1) break; * C2 * * do{ C2=base64decodechars[str.charcodeat (i++) &0xff]; }while (I<len&&c2==-1); if (c2==-1) break; Out+=string.fromcharcode ((c1<<2) | ( (c2&0x30) >>4)); * C3 * * do{ C3=str.charcodeat (i++) &0xff; if (c3==61) return out; C3=BASE64DECODECHARS[C3]; }while (I<len&&c3==-1); if (c3==-1) break; Out+=string.fromcharcode ((c2&0xf) <<4) | ( (c3&0x3c) >>2)); * C4 * * do{ C4=str.charcodeat (i++) &0xff; if (c4==61) return out; C4=BASE64DECODECHARS[C4]; }while (I<len&&c4==-1); if (c4==-1) break; Out+=string.fromcharcode (((c3&0x03) <<6) |c4); } return out; } function Utf16to8 (str) { var out,i,len,c; Out= ""; Len=str.length; for (i=0;i<len;i++) { C=str.charcodeat (i); if ((c>=0x0001) && (c<=0x007f)) { Out+=str.charat (i); else if (c>0x07ff) { Out+=string.fromcharcode (0xe0| ( (c>>12) &0x0f)); Out+=string.fromcharcode (0x80| ( (c>>6) &0x3f)); Out+=string.fromcharcode (0x80| ( (c>>0) &0x3f)); } else { Out+=string.fromcharcode (0xc0| ( (c>>6) &0x1f)); Out+=string.fromcharcode (0x80| ( (c>>0) &0x3f)); } } return out; } function Utf8to16 (str) { var out,i,len,c; var char2,char3; Out= ""; Len=str.length; i=0; while (I<len) { C=str.charcodeat (i++); Switch (c>>4) { Case 0: Case 1: Case 2: Case 3: Case 4: Case 5: Case 6: Case 7: 0xxxxxxx Out+=str.charat (i-1); Break Case 12: Case 13: 110x xxxx 10xx xxxx Char2=str.charcodeat (i++); Out+=string.fromcharcode ((c&0x1f) <<6) | ( char2&0x3f)); Break Case 14: 1110 xxxx 10xx xxxx 10xx xxxx Char2=str.charcodeat (i++); Char3=str.charcodeat (i++); Out+=string.fromcharcode ((c&0x0f) <<12) | ( (char2&0x3f) <<6) | ((char3&0x3f) <<0)); Break } } return out; } |