diff --git a/utils/base32 b/utils/base32 new file mode 100755 index 0000000..aa2afe1 --- /dev/null +++ b/utils/base32 @@ -0,0 +1,31 @@ +#!/bin/bash + +usage () { + echo "This is a replacement for base32 (from GNU coreutils), which is not easily available on ci-centos machines. + +Usage: + pipe content to be encoded into this executable, or pipe content with -d to decode. + +Examples: + echo 'some string that I used to know' | $0 # ONXW2ZJAON2HE2LOM4QHI2DBOQQESIDVONSWIIDUN4QGW3TPO4====== + echo 'ONXW2ZJAON2HE2LOM4QHI2DBOQQESIDVONSWIIDUN4QGW3TPO4======' | $0 -d # some string that I used to know +" + exit +} + +DECODE=0 +for i in "$@" +do +case $i in + -d) DECODE=1; shift;; + --help|--version) usage; shift;; +esac +done + +read -t 60 TEXT + +if [ $DECODE -eq 1 ];then + python3 -c "import base64; print(base64.b32decode(bytearray('$TEXT', 'ascii')).decode('utf-8'))" +else + python3 -c "import base64; print(base64.b32encode(bytearray('$TEXT', 'ascii')).decode('utf-8'))" +fi \ No newline at end of file