Skip to content

Instantly share code, notes, and snippets.

@voyagerwoo
Last active December 15, 2017 07:43
Show Gist options
  • Select an option

  • Save voyagerwoo/42567efadb8510334e502592d53302b5 to your computer and use it in GitHub Desktop.

Select an option

Save voyagerwoo/42567efadb8510334e502592d53302b5 to your computer and use it in GitHub Desktop.
base64.js
const BASE64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
function encodeBASE64(value) {
value = parseInt(value);
if (!value) throw new Error("Not a integer value.")
let result = "";
do {
result += BASE64[value % 64];
value = parseInt(value / 64);
} while (value > 0);
return result;
}
for (var i=0; i<20; i ++) {
console.log("date : ", encodeBASE64(new Date().getTime()));
console.log("random : ", encodeBASE64(Math.random() * 64 * 64 * 64));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment