line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::Ascii85; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
47878
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
101
|
|
4
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
155
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
17
|
use Exporter qw(import); |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
1845
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(ascii85_encode ascii85_decode); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $_space_no = unpack 'N', ' ' x 4; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub encode { |
15
|
11
|
|
|
11
|
1
|
4511
|
my ($in, $opt) = @_; |
16
|
11
|
100
|
|
|
|
30
|
my $compress_zero = exists $opt->{compress_zero} ? $opt->{compress_zero} : 1; |
17
|
11
|
|
|
|
|
16
|
my $compress_space = $opt->{compress_space}; |
18
|
|
|
|
|
|
|
|
19
|
11
|
|
|
|
|
19
|
my $padding = -length($in) % 4; |
20
|
11
|
|
|
|
|
19
|
$in .= "\0" x $padding; |
21
|
11
|
|
|
|
|
12
|
my $out = ''; |
22
|
|
|
|
|
|
|
|
23
|
11
|
|
|
|
|
38
|
for my $n (unpack 'N*', $in) { |
24
|
86
|
100
|
100
|
|
|
197
|
if ($n == 0 && $compress_zero) { |
25
|
7
|
|
|
|
|
8
|
$out .= 'z'; |
26
|
7
|
|
|
|
|
15
|
next; |
27
|
|
|
|
|
|
|
} |
28
|
79
|
100
|
100
|
|
|
156
|
if ($n == $_space_no && $compress_space) { |
29
|
1
|
|
|
|
|
2
|
$out .= 'y'; |
30
|
1
|
|
|
|
|
2
|
next; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
78
|
|
|
|
|
65
|
my $tmp = ''; |
34
|
78
|
|
|
|
|
94
|
for my $i (reverse 0 .. 4) { |
35
|
390
|
|
|
|
|
340
|
my $mod = $n % 85; |
36
|
390
|
|
|
|
|
360
|
$n = int($n / 85); |
37
|
390
|
|
|
|
|
662
|
vec($tmp, $i, 8) = $mod + 33; |
38
|
|
|
|
|
|
|
} |
39
|
78
|
|
|
|
|
108
|
$out .= $tmp; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
11
|
100
|
|
|
|
66
|
$padding or return $out; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
19
|
$out =~ s/z\z/!!!!!/; |
45
|
7
|
|
|
|
|
33
|
substr $out, 0, length($out) - $padding |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
*ascii85_encode = \&encode; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub decode { |
51
|
11
|
|
|
11
|
1
|
16
|
my ($in) = @_; |
52
|
11
|
|
|
|
|
22
|
for ($in) { |
53
|
11
|
|
|
|
|
18
|
tr[ \t\r\n\f][]d; |
54
|
11
|
|
|
|
|
23
|
s/z/!!!!!/g; |
55
|
11
|
|
|
|
|
23
|
s/y/+
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
11
|
|
|
|
|
21
|
my $padding = -length($in) % 5; |
59
|
11
|
|
|
|
|
14
|
$in .= 'u' x $padding; |
60
|
11
|
|
|
|
|
29
|
my $out = ''; |
61
|
|
|
|
|
|
|
|
62
|
11
|
|
|
|
|
56
|
for my $n (unpack '(a5)*', $in) { |
63
|
86
|
|
|
|
|
74
|
my $tmp = 0; |
64
|
86
|
|
|
|
|
112
|
for my $i (unpack 'C*', $n) { |
65
|
430
|
|
|
|
|
332
|
$tmp *= 85; |
66
|
430
|
|
|
|
|
399
|
$tmp += $i - 33; |
67
|
|
|
|
|
|
|
} |
68
|
86
|
|
|
|
|
156
|
$out .= pack 'N', $tmp; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
11
|
|
|
|
|
132
|
substr $out, 0, length($out) - $padding |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
*ascii85_decode = \&decode; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |