Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 6 down vote accepted

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:

$ sudo apt-get install libmime-base32-perl

And then a script like base32enc.pl:

#!/usr/bin/perl

use MIME::Base32 qw( RFC );

undef $/;  # in case stdin has newlines
$string = <STDIN>;

$encoded = MIME::Base32::encode($string);

print "$encoded\n";

So:

$ echo -n "hello" | ./base32enc.pl
NBSWY3DP

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.

share|improve this answer
1  
Thanks, MIME::Base32 seems to do the trick. –  jdev May 4 '12 at 22:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.