Skip to content

Instantly share code, notes, and snippets.

@siberex
Last active May 28, 2020 15:13
Show Gist options
  • Save siberex/9088525 to your computer and use it in GitHub Desktop.
Save siberex/9088525 to your computer and use it in GitHub Desktop.
// Solution by broc.seib from http://stackoverflow.com/a/15016605/1412330
// Here exists better decoding (not encoding) solution: http://jsbase64.codeplex.com/
// Comparisons between my encoding and solutions from Stackvverflow are here https://gist.github.com/siberex/9089425
decodeBase64 = 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