xcorp::When it rains, it pours.

"The nice thing about rain," said Eeyore, "is that it always stops. Eventually."

続 Base64

続き
まずは Perl で。

[xcorp@yield ~]$ cat base64.pl
#!/usr/bin/perl

use strict;
use MIME::Base64;
use Getopt::Long;

my $optDecode = 0;
GetOptions('d' => \$optDecode);

while (<>) {
        $optDecode == 0 ? print encode_base64($_) : print decode_base64($_) . "\n";
}
[xcorp@yield ~]$ echo -n "hello world" | ./base64.pl
aGVsbG8gd29ybGQ=
[xcorp@yield ~]$ echo -n "aGVsbG8gd29ybGQ=" | ./base64.pl -d
hello world
[xcorp@yield ~]$

ふむ。こんなもんか。
続いて Ruby

[xcorp@yield ~]$ cat base64.rb
#!/usr/bin/ruby --

require 'optparse'

isDecode = false
opts = OptionParser.new
opts.on('-d') { |v| isDecode = true }
opts.parse!
lines = readlines
lines.each { |line|
        isDecode ? puts(line.unpack('m')) : puts([line].pack('m'))
}
[xcorp@yield ~]$ echo -n "hello world" | ./base64.rb
aGVsbG8gd29ybGQ=
[xcorp@yield ~]$ echo -n "aGVsbG8gd29ybGQ=" | ./base64.rb -d
hello world
[xcorp@yield ~]$

お次は Python…とか思ったけど、めんどくさくなってやめてしまったよ(;´Д`)