function encode_base64(psstr) { return encode(psstr,psstr.length); } function encode (psstrs, iLen) { var map1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var oDataLen = (iLen*4+2)/3; var oLen = ((iLen+2)/3)*4; var out=''; var ip = 0; var op = 0; while (ip < iLen) { var xx = psstrs.charCodeAt(ip++); var yy = ip < iLen ? psstrs.charCodeAt(ip++) : 0; var zz = ip < iLen ? psstrs.charCodeAt(ip++) : 0; var aa = xx >>> 2; var bb = ((xx & 3) << 4) | (yy >>> 4); var cc = ((yy & 0xf) << 2) | (zz >>> 6); var dd = zz & 0x3F; out += map1.charAt(aa); op++; out += map1.charAt(bb); op++; out += op < oDataLen ? map1.charAt(cc) : '='; op++; out += op < oDataLen ? map1.charAt(dd) : '='; op++; } return out; }