line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Encode;
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62;
|
4
|
1
|
|
|
1
|
|
1015
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
6
|
use Digest::MD5 qw(md5);
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
841
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter;
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(nonuniform uniform) ] );
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.00';
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub uniform ($) {
|
19
|
0
|
|
|
0
|
1
|
|
my $data = shift;
|
20
|
0
|
|
|
|
|
|
my $char = 0;
|
21
|
0
|
|
|
|
|
|
my $carry = 0;
|
22
|
0
|
|
|
|
|
|
my $cbits = 0;
|
23
|
0
|
|
|
|
|
|
my $hsh = '';
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
for my $c (split(//, $data))
|
26
|
|
|
|
|
|
|
{
|
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$carry <<= 8;
|
29
|
0
|
|
|
|
|
|
$carry += ord($c);
|
30
|
0
|
|
|
|
|
|
$cbits += 8;
|
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
while ($cbits >= 4) {
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $n;
|
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if ($cbits >= 4) { # More than 4 bits available
|
37
|
0
|
|
|
|
|
|
$n = $carry & 0xF;
|
38
|
0
|
0
|
|
|
|
|
if ($n > 9) {
|
39
|
0
|
|
|
|
|
|
$n ^= vec(md5($hsh . $carry . $n), $n, 4);
|
40
|
0
|
0
|
|
|
|
|
$n &= 0x7 if $n > 9;
|
41
|
|
|
|
|
|
|
}
|
42
|
0
|
|
|
|
|
|
$carry >>= 4;
|
43
|
0
|
|
|
|
|
|
$cbits -= 4;
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$hsh .= chr(ord('0') + $n);
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if ($cbits) {
|
51
|
0
|
|
|
|
|
|
$hsh .= chr(ord('0') + $carry);
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $hsh;
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub nonuniform ($) {
|
58
|
0
|
|
|
0
|
1
|
|
my $data = shift;
|
59
|
0
|
|
|
|
|
|
my $char = 0;
|
60
|
0
|
|
|
|
|
|
my $carry = 0;
|
61
|
0
|
|
|
|
|
|
my $cbits = 0;
|
62
|
0
|
|
|
|
|
|
my $hsh = '';
|
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for my $c (split(//, $data))
|
65
|
|
|
|
|
|
|
{
|
66
|
0
|
|
|
|
|
|
$carry <<= 256;
|
67
|
0
|
|
|
|
|
|
$carry += ord($c);
|
68
|
0
|
|
|
|
|
|
$cbits += 8;
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
while ($cbits >= 4) {
|
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $n;
|
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($cbits >= 4) { # More than 4 bits available
|
75
|
0
|
|
|
|
|
|
$n = $carry & 0xF;
|
76
|
0
|
0
|
|
|
|
|
if ($n <= 9) {
|
77
|
0
|
|
|
|
|
|
$carry >>= 4;
|
78
|
0
|
|
|
|
|
|
$cbits -= 4;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
0
|
|
|
|
if ($cbits == 3 or $n > 9) {
|
83
|
0
|
|
|
|
|
|
$n = $carry & 0x7;
|
84
|
0
|
|
|
|
|
|
$carry >>= 3;
|
85
|
0
|
|
|
|
|
|
$cbits -= 3;
|
86
|
|
|
|
|
|
|
}
|
87
|
0
|
|
|
|
|
|
$hsh .= chr(ord('0') + $n);
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ($cbits) {
|
92
|
0
|
|
|
|
|
|
$hsh .= chr(ord('0') + $carry);
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $hsh;
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1;
|
99
|
|
|
|
|
|
|
__END__
|