Skip to content

Instantly share code, notes, and snippets.

@whaaaley
Created January 4, 2017 00:54
Show Gist options
  • Save whaaaley/a78546757a4d5580a606adb6fe516d48 to your computer and use it in GitHub Desktop.
Save whaaaley/a78546757a4d5580a606adb6fe516d48 to your computer and use it in GitHub Desktop.
function btoa(v) {
var l=v.length,i=(~~(l/3)+1)*4,n,c='',r='',e=0,s,t,q,h='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
while(--i){
if(l-->0){
n=v[v.length-1-l].charCodeAt().toString(2)
c=c+('00000000'.substr(n.length)+n)
}
s=c.substr(e,6)
r=r+h[parseInt(s,2)]
e=e+6
}
t=s.length
q=t<8?t<7?'=':'':'=='
return r+q
}
function btoa2(v){
for(var e=v.length,i=(~~(e/3)+1)*4;e;--e) {
console.log(e)
}
// return r
}
var wikipedia = 'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.'
// var b = btoa(wikipedia)
var b = btoa2(wikipedia)
console.log(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment