"use strict";var utils=require("./utils"),support=require("./support"),_keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";exports.encode=function(r){for(var t,e,a,n,h,c,A,i=[],o=0,u=r.length,y=u,s="string"!==utils.getTypeOf(r);o<r.length;)y=u-o,s?(t=r[o++],e=o<u?r[o++]:0,a=o<u?r[o++]:0):(t=r.charCodeAt(o++),e=o<u?r.charCodeAt(o++):0,a=o<u?r.charCodeAt(o++):0),n=t>>2,h=(3&t)<<4|e>>4,c=y>1?(15&e)<<2|a>>6:64,A=y>2?63&a:64,i.push(_keyStr.charAt(n)+_keyStr.charAt(h)+_keyStr.charAt(c)+_keyStr.charAt(A));return i.join("")},exports.decode=function(r){var t,e,a,n,h,c,A,i=0,o=0;r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");var u=3*r.length/4;r.charAt(r.length-1)===_keyStr.charAt(64)&&u--,r.charAt(r.length-2)===_keyStr.charAt(64)&&u--;var y;for(y=support.uint8array?new Uint8Array(u):new Array(u);i<r.length;)n=_keyStr.indexOf(r.charAt(i++)),h=_keyStr.indexOf(r.charAt(i++)),c=_keyStr.indexOf(r.charAt(i++)),A=_keyStr.indexOf(r.charAt(i++)),t=n<<2|h>>4,e=(15&h)<<4|c>>2,a=(3&c)<<6|A,y[o++]=t,64!==c&&(y[o++]=e),64!==A&&(y[o++]=a);return y};