Created
November 3, 2016 08:15
-
-
Save greymd/59781d9132cc4f67229896a57638133a to your computer and use it in GitHub Desktop.
base64 encoder given by build-in linux commands.
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
base64sh() { | |
local input=${1:-$(cat)} | |
paste <(seq 0 63 | sed 's/^/obase=2;ibase=10;/' | bc | sed 's/^/00000/' | grep -oE '.{6}$') \ | |
<(echo {A..Z} {a..z} {0..9} + / | xargs -n 1) | \ | |
awk '{print "s|"$1"|"$2"|"}' | \ | |
sed -f - <(echo -n $input| perl -ne 'print unpack("B*", $_)."0000"' | \ | |
fold -w 6 | grep -oE '.{6}$') | tr -d '\n' | fold -w 4 | sed 's/$/===/' | grep -oE '^.{4}' | tr -d '\n' | awk 1 | |
} | |
# Usage: base64sh | |
# | |
# $ echo Yes高須クリニック | base64sh | |
# WWVz6auY6aCI44Kv44Oq44OL44OD44Kv | |
# | |
# $ base64sh 'This is a pen' | |
# VGhpcw== | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment