Last active
December 15, 2017 07:43
-
-
Save voyagerwoo/42567efadb8510334e502592d53302b5 to your computer and use it in GitHub Desktop.
base64.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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