-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathRSA_PRNG.pl
executable file
·54 lines (41 loc) · 1010 Bytes
/
RSA_PRNG.pl
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
53
54
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 19 January 2017
# https://github.com/trizen
# A concept for a new pseudorandom number generator,
# based on the idea of the RSA encryption algorithm.
# Under development and analysis...
use 5.010;
use strict;
use warnings;
use Math::AnyNum qw(gcd irand powmod);
use ntheory qw(random_strong_prime);
{
my $p = Math::AnyNum->new(random_strong_prime(256));
my $q = Math::AnyNum->new(random_strong_prime(256));
my $n = $p * $q;
my $phi = ($p - 1) * ($q - 1);
my $e;
#<<<
do {
$e = irand(65537, $n);
} until (
$e < $phi
and gcd($e, $phi ) == 1
and gcd($e - 1, $p - 1) == 2
and gcd($e - 1, $q - 1) == 2
);
#>>>
sub RSA_PRNG {
my ($seed) = @_;
my $state = abs($seed);
sub {
$state = powmod($state + 11, $e, $n) & 0x7fff_ffff;
};
}
}
my $rand = RSA_PRNG(42);
foreach my $i (1 .. 20) {
say $rand->();
}