I'm looking to encode an input string to base32 encoding directly from the shell. I'm looking to do this in ubuntu, but I imagine flavor doesn't particularly matter here.
Are there any existing linux/unix tools out there to simply do this?
Something along the lines of:
-bash-3.2$ echo -n 'hello' | base32
Hmm, a quick package search doesn't give anything like a single, standalone utility.
On the other hand, it shows that there's an appropriate Perl library, and it's easy enough to whip up a quick perl script. Something like:
And then a script like
base32enc.pl
:So:
The fairly sparse CPAN entry is: http://search.cpan.org/~danpeder/MIME-Base32-1.01/Base32.pm
So, a minor change will let you do decodes, also.
It's installed by default in Ubuntu 16.04 as part of coreutils:
Using Python:
Just an improvement of cjc excellent answer so we can have a
base32
utility which works similarly tobase64
in the way we can encode and decode:Test:
Install
perl-MIME-Base32.noarch
:Save the script in bas32 filename: