2015-04-02 20:32:22 +00:00
|
|
|
var Base64 = (function make_b64(){
|
|
|
|
var map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
|
|
return {
|
2017-05-09 18:07:57 +00:00
|
|
|
encode: function(input/*:string*/)/*:string*/ {
|
2015-04-02 20:32:22 +00:00
|
|
|
var o = "";
|
2017-11-20 01:51:14 +00:00
|
|
|
var c1=0, c2=0, c3=0, e1=0, e2=0, e3=0, e4=0;
|
2015-04-02 20:32:22 +00:00
|
|
|
for(var i = 0; i < input.length; ) {
|
|
|
|
c1 = input.charCodeAt(i++);
|
|
|
|
c2 = input.charCodeAt(i++);
|
|
|
|
c3 = input.charCodeAt(i++);
|
|
|
|
e1 = c1 >> 2;
|
2017-11-20 01:51:14 +00:00
|
|
|
e2 = ((c1 & 3) << 4) | (c2 >> 4);
|
|
|
|
e3 = ((c2 & 15) << 2) | (c3 >> 6);
|
2015-04-02 20:32:22 +00:00
|
|
|
e4 = c3 & 63;
|
|
|
|
if (isNaN(c2)) { e3 = e4 = 64; }
|
|
|
|
else if (isNaN(c3)) { e4 = 64; }
|
|
|
|
o += map.charAt(e1) + map.charAt(e2) + map.charAt(e3) + map.charAt(e4);
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
},
|
2017-05-09 18:07:57 +00:00
|
|
|
decode: function b64_decode(input/*:string*/)/*:string*/ {
|
2015-04-02 20:32:22 +00:00
|
|
|
var o = "";
|
2017-11-20 01:51:14 +00:00
|
|
|
var c1=0, c2=0, c3=0;
|
|
|
|
var e1=0, e2=0, e3=0, e4=0;
|
2015-04-02 20:32:22 +00:00
|
|
|
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
|
|
|
for(var i = 0; i < input.length;) {
|
|
|
|
e1 = map.indexOf(input.charAt(i++));
|
|
|
|
e2 = map.indexOf(input.charAt(i++));
|
|
|
|
e3 = map.indexOf(input.charAt(i++));
|
|
|
|
e4 = map.indexOf(input.charAt(i++));
|
2017-11-20 01:51:14 +00:00
|
|
|
c1 = (e1 << 2) | (e2 >> 4);
|
|
|
|
c2 = ((e2 & 15) << 4) | (e3 >> 2);
|
|
|
|
c3 = ((e3 & 3) << 6) | e4;
|
2015-04-02 20:32:22 +00:00
|
|
|
o += String.fromCharCode(c1);
|
2017-11-20 01:51:14 +00:00
|
|
|
if (e3 !== 64) { o += String.fromCharCode(c2); }
|
|
|
|
if (e4 !== 64) { o += String.fromCharCode(c3); }
|
2015-04-02 20:32:22 +00:00
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|