3 lines
1.3 KiB
JavaScript
3 lines
1.3 KiB
JavaScript
|
function Base64(){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";this.encode=function(e){var r="",o,a,d,h,C,f,t,c=0;for(e=i(e);c<e.length;)o=e.charCodeAt(c++),a=e.charCodeAt(c++),d=e.charCodeAt(c++),h=o>>2,C=(o&3)<<4|a>>4,f=(a&15)<<2|d>>6,t=d&63,isNaN(a)?f=t=64:isNaN(d)&&(t=64),r=r+n.charAt(h)+n.charAt(C)+n.charAt(f)+n.charAt(t);return r},this.decode=function(e){var r="",o,a,d,h,C,f,t,c=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");c<e.length;)h=n.indexOf(e.charAt(c++)),C=n.indexOf(e.charAt(c++)),f=n.indexOf(e.charAt(c++)),t=n.indexOf(e.charAt(c++)),o=h<<2|C>>4,a=(C&15)<<4|f>>2,d=(f&3)<<6|t,r=r+String.fromCharCode(o),f!=64&&(r=r+String.fromCharCode(a)),t!=64&&(r=r+String.fromCharCode(d));return r=v(r),r};var i=function(e){e=e.replace(/\r\n/g,`
|
||
|
`);for(var r="",o=0;o<e.length;o++){var a=e.charCodeAt(o);a<128?r+=String.fromCharCode(a):a>127&&a<2048?(r+=String.fromCharCode(a>>6|192),r+=String.fromCharCode(a&63|128)):(r+=String.fromCharCode(a>>12|224),r+=String.fromCharCode(a>>6&63|128),r+=String.fromCharCode(a&63|128))}return r},v=function(e){for(var r="",o=0,a=0,d=0,h=0,C=0;o<e.length;)a=e.charCodeAt(o),a<128?(r+=String.fromCharCode(a),o++):a>191&&a<224?(h=e.charCodeAt(o+1),r+=String.fromCharCode((a&31)<<6|h&63),o+=2):(h=e.charCodeAt(o+1),C=e.charCodeAt(o+2),r+=String.fromCharCode((a&15)<<12|(h&63)<<6|C&63),o+=3);return r}}
|