Skip to content

Instantly share code, notes, and snippets.

@anbinh
Forked from bytespider/LICENSE.txt
Last active December 15, 2015 14:29
Show Gist options
  • Save anbinh/5275155 to your computer and use it in GitHub Desktop.
Save anbinh/5275155 to your computer and use it in GitHub Desktop.
Base64 Encode
function base64Encode(
a, // string to encode
b, // character table ie, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
c, // placeholder
d, // placeholder
e, // placeholder
f, // placeholder
g, // placeholder
h // placeholder
){
h="";
for(d=0; // initialise the output buffer
a[d]; // check if a value is returned
h+=b[e>>2]+b[e<<4&63|f>>4]+b[f<<2&63|g>>6||64]+b[g&63||64]) // split into 6bits characters and find it in our character table
for(c=4;c<7;)
arguments[c++]=a.charCodeAt(d++) // copy the character code into a variable declared as a placeholder
return h
}
function(a,b,c,d,e,f,g,h){h="";for(d=0;a[d];h+=b[e>>2]+b[e<<4&63|f>>4]+b[f<<2&63|g>>6||64]+b[g&63||64])for(c=4;c<7;)arguments[c++]=a.charCodeAt(d++);return h}
{
"name": "Base64 Encode",
"keywords": [
"140bytes",
"base64",
"encode"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment