-
-
Save hh-lohmann/97a73991214035565c8ce1aeeee4b9cc to your computer and use it in GitHub Desktop.
BASH base 62 encode / decode
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
#!/usr/bin/env bash | |
# https://gist.github.com/BobbyRyterski/7a511b96ece47655b17d | |
# based on http://stackoverflow.com/q/14471692 | |
readonly BASE62=($(echo {0..9} {a..z} {A..Z})) | |
base62_encode() { | |
local out= | |
for i in $(bc <<< "obase=62; $1"); do | |
out="${out}${BASE62[$((10#$i))]}" | |
done | |
echo $out | |
} | |
base62_decode() { | |
echo $((62#$1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment