Skip to content

Instantly share code, notes, and snippets.

@petvas
Created March 28, 2016 22:17
Show Gist options
  • Save petvas/1da4968eb70485a37fe9 to your computer and use it in GitHub Desktop.
Save petvas/1da4968eb70485a37fe9 to your computer and use it in GitHub Desktop.
var codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-_".split('');
function to64(d) {
var r = d % 64;
var result;
if (d - r == 0)
result = codes[r];
else
result = to64((d - r) / 64) + codes[r];
return result;
}
function from64(d) {
var result = 0;
d.split('').forEach(function (c, i) {
console.log(codes.indexOf(c), d.length - i);
result += (codes.indexOf(c)) * (((d.length - i - 1) * 64 ) || 1);
});
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment