-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathb64
executable file
·52 lines (48 loc) · 813 Bytes
/
b64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
#
# convert base64 to ascii
# ignore lines starting with ---
my $out = -t STDOUT ? "\n" : "";
use MIME::Base64;
use strict;
my $type = shift;
if ($type eq "-d")
{
if (@ARGV)
{
print decode($_) . $out for @ARGV;
}
else
{
print decode($_) while <>;
}
}
elsif ($type eq "-e")
{
if (@ARGV)
{
print MIME::Base64::encode_base64($_) for @ARGV;
}
else
{
print MIME::Base64::encode_base64(join("", <>));
}
}
else
{
die "usage: $0 <-d | -e> [data | STDIN]\n";
}
sub decode
{
chomp($_[0]);
if ($_[0] =~ /^---/)
{
print STDERR "NOTICE: Ignoring line: $_\n";
return "";
}
elsif ($_[0] =~ m|[^A-Za-z0-9+/=]|)
{
print STDERR "WARNING: Ignoring chars: " . join(",", $_[0] =~ m|([^A-Za-z0-9+/=]+)|g) . "\n";
}
return MIME::Base64::decode_base64($_[0]);
}