line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Perl::Math; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
131184
|
use strict; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
202
|
|
4
|
8
|
|
|
8
|
|
33
|
use warnings; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
176
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
395
|
use Crypt::Perl::BigInt (); |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
93
|
|
7
|
8
|
|
|
8
|
|
2747
|
use Crypt::Perl::RNG (); |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
1083
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub ceil { |
10
|
66
|
50
|
|
66
|
0
|
56352
|
return int($_[0]) if $_[0] <= 0; |
11
|
|
|
|
|
|
|
|
12
|
66
|
|
|
|
|
388
|
return int($_[0]) + int( !!($_[0] - int $_[0]) ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#limit is inclusive |
16
|
|
|
|
|
|
|
#cf. Python’s random.randint() |
17
|
|
|
|
|
|
|
sub randint { |
18
|
324
|
|
|
324
|
0
|
20785
|
my ($limit) = @_; |
19
|
|
|
|
|
|
|
|
20
|
324
|
|
|
|
|
764
|
my $limit_bit_count; |
21
|
324
|
100
|
66
|
|
|
4489
|
if (ref($limit) && (ref $limit)->isa('Math::BigInt')) { |
22
|
304
|
|
|
|
|
1375
|
$limit_bit_count = length($limit->as_bin()) - 2; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#Is this ever needed?? |
26
|
|
|
|
|
|
|
else { |
27
|
20
|
|
|
|
|
62
|
$limit_bit_count = length sprintf '%b', $limit; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
324
|
|
|
|
|
272906
|
my $rand; |
31
|
324
|
|
|
|
|
903
|
do { |
32
|
430
|
|
|
|
|
445771
|
$rand = Crypt::Perl::BigInt->from_bin( Crypt::Perl::RNG::bit_string($limit_bit_count) ); |
33
|
|
|
|
|
|
|
} while $rand > $limit; |
34
|
|
|
|
|
|
|
|
35
|
324
|
|
|
|
|
1424511
|
return $rand; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |