Last active
January 3, 2021 18:25
-
-
Save dajare/721c1ca973d7325efb69ba71b5731920 to your computer and use it in GitHub Desktop.
Shell script to convert unix timestamp to base36 (alphanumeric, lowercase)
This file contains 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
#!/bin/bash | |
# takes unix timestamp and converts to base36 | |
# ht: https://en.wikipedia.org/wiki/Base36#bash_implementation | |
value=$(date +%s) | |
result="" | |
base36="0123456789abcdefghijklmnopqrstuvwxyz" | |
while true; do | |
result=${base36:((value%36)):1}${result} | |
if [ $((value=${value}/36)) -eq 0 ]; then | |
break | |
fi | |
done | |
echo ${result} |
Nice base36 converter.
The openssl (and unix) base64
algorithm is for encoding binary data into ASCII strings, not for converting integers to different radix (numeric base). https://en.wikipedia.org/wiki/Base64
To convert an integer to an exotic numeric base you'll need something like these: https://stackoverflow.com/questions/14471692/bash-decimal-to-base-62-conversion
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@caorongjin said:
LOL. @typora actually is a bit weird in handling case differences. I'll do a bit of testing, and if I can work out the pattern, will post a bug report.