4 _keyStr
: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
6 // public method for encoding
7 encode
: function (input
) {
9 var chr1
, chr2
, chr3
, enc1
, enc2
, enc3
, enc4
;
12 input
= Base64
._utf8_encode(input
);
14 while (i
< input
.length
) {
16 chr1
= input
.charCodeAt(i
++);
17 chr2
= input
.charCodeAt(i
++);
18 chr3
= input
.charCodeAt(i
++);
21 enc2
= ((chr1
& 3) << 4) |
(chr2
>> 4);
22 enc3
= ((chr2
& 15) << 2) |
(chr3
>> 6);
27 } else if (isNaN(chr3
)) {
32 this._keyStr
.charAt(enc1
) + this._keyStr
.charAt(enc2
) +
33 this._keyStr
.charAt(enc3
) + this._keyStr
.charAt(enc4
);
40 // public method for decoding
41 decode
: function (input
) {
44 var enc1
, enc2
, enc3
, enc4
;
47 input
= input
.replace(/[^A
-Za
-z0
-9\
+\
/\
=]/g
, "");
49 while (i
< input
.length
) {
51 enc1
= this._keyStr
.indexOf(input
.charAt(i
++));
52 enc2
= this._keyStr
.indexOf(input
.charAt(i
++));
53 enc3
= this._keyStr
.indexOf(input
.charAt(i
++));
54 enc4
= this._keyStr
.indexOf(input
.charAt(i
++));
56 chr1
= (enc1
<< 2) |
(enc2
>> 4);
57 chr2
= ((enc2
& 15) << 4) |
(enc3
>> 2);
58 chr3
= ((enc3
& 3) << 6) | enc4
;
60 output
= output
+ String
.fromCharCode(chr1
);
63 output
= output
+ String
.fromCharCode(chr2
);
66 output
= output
+ String
.fromCharCode(chr3
);
71 output
= Base64
._utf8_decode(output
);
77 // private method for UTF-8 encoding
78 _utf8_encode
: function (string
) {
79 string
= string
.replace(/\r\n/g
,"\n");
82 for (var n
= 0; n
< string
.length
; n
++) {
84 var c
= string
.charCodeAt(n
);
87 utftext
+= String
.fromCharCode(c
);
89 else if((c
> 127) && (c
< 2048)) {
90 utftext
+= String
.fromCharCode((c
>> 6) |
192);
91 utftext
+= String
.fromCharCode((c
& 63) |
128);
94 utftext
+= String
.fromCharCode((c
>> 12) |
224);
95 utftext
+= String
.fromCharCode(((c
>> 6) & 63) |
128);
96 utftext
+= String
.fromCharCode((c
& 63) |
128);
104 // private method for UTF-8 decoding
105 _utf8_decode
: function (utftext
) {
110 while ( i
< utftext
.length
) {
112 c
= utftext
.charCodeAt(i
);
115 string
+= String
.fromCharCode(c
);
118 else if((c
> 191) && (c
< 224)) {
119 c2
= utftext
.charCodeAt(i
+1);
120 string
+= String
.fromCharCode(((c
& 31) << 6) |
(c2
& 63));
124 c2
= utftext
.charCodeAt(i
+1);
125 c3
= utftext
.charCodeAt(i
+2);
126 string
+= String
.fromCharCode(((c
& 15) << 12) |
((c2
& 63) << 6) |
(c3
& 63));