Skip to content

Instantly share code, notes, and snippets.

@MrPoofy
Created April 22, 2014 09:49
Show Gist options
  • Save MrPoofy/11172385 to your computer and use it in GitHub Desktop.
Save MrPoofy/11172385 to your computer and use it in GitHub Desktop.
Decoder for base64 strings.
/* ==========================================================================
Decoder for Base64 strings.
Created by Broc Seib @http://blog.broc.seib.net
========================================================================== */
decode_Base64 = function(s) {
var e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;
var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for(i=0;i<64;i++){e[A.charAt(i)]=i;}
for(x=0;x<L;x++){
c=e[s.charAt(x)];b=(b<<6)+c;l+=6;
while(l>=8){((a=(b>>>(l-=8))&0xff)||(x<(L-2)))&&(r+=w(a));}
}
return r;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment