Answers:
嗯,快速的软件包搜索并没有像单个独立的实用程序那样的东西。
另一方面,它表明存在一个合适的Perl库,并且很容易生成快速的Perl脚本。就像是:
$ sudo apt-get install libmime-base32-perl
然后是一个脚本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";
所以:
$ echo -n "hello" | ./base32enc.pl
NBSWY3DP
相对稀疏的CPAN条目是:http : //search.cpan.org/~danpeder/MIME-Base32-1.01/Base32.pm
因此,只需稍作更改,即可进行解码。
只是对cjc最佳答案的一种改进,因此我们可以使用与编码和解码方式base32
类似的实用程序base64
:
#! /usr/bin/perl
use MIME::Base32;
use strict;
undef $/;
my $string = <STDIN>;
my $changed;
if ( $ARGV[0] eq "-d" ){
$changed = MIME::Base32::decode($string);
}else{
$changed = MIME::Base32::encode($string);
}
if ( $changed =~ /\n$/ ) {
printf $changed;
}else{
printf $changed . "\n";
}
测试:
$ base32 < <(echo -n 'abcdef')
MFRGGZDFMY
$ base32 -d < <(echo 'MFRGGZDFMY')
abcdef
默认情况下,它作为coreutils的一部分安装在Ubuntu 16.04中:
$ which base32
/usr/bin/base32
安装perl-MIME-Base32.noarch
:
yum install perl-MIME-Base32.noarch
将脚本保存在bas32文件名中:
#!/usr/bin/perl
use MIME::Base32 qw( RFC );
undef $/; # in case stdin has newlines
$ed=$ARGV[0];
$string=$ARGV[1];
if ($ed eq "-e")
{
$encoded = MIME::Base32::encode($string);
print "$encoded\n";
}
elsif ($ed eq "-d")
{
$decoded = MIME::Base32::decode($string);
print "$decoded\n";
}
else { print " please pass option also\n";
exit;
}
chmod +x base32
cp base32 /usr/bin/
base32 -e string
base32 -d "any encoded value"