-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
57 lines (47 loc) · 1.1 KB
/
main.cpp
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
55
56
57
// CC0 1.0 Universal (CC0 1.0)
// Public Domain Dedication
// https://github.com/nmrr
#include <iostream>
#include <random>
#include <gmpxx.h>
using namespace std;
mpz_class getPrime(size_t size, bool checksize=false)
{
random_device rnd;
uniform_int_distribution<> dist(0, 1);
mpz_class prime;
if (size <2) size = 2;
while(1)
{
string numberString = "1";
for (size_t i=1; i<size; i++)
{
numberString += to_string(dist(rnd));
}
mpz_class n(numberString,2);
if (mpz_probab_prime_p(n.get_mpz_t(), 50) != 0)
{
prime = n;
}
else
{
mpz_nextprime(prime.get_mpz_t(), n.get_mpz_t());
}
if (checksize == true)
{
if (mpz_sizeinbase(prime.get_mpz_t(), 2) == size) break;
}
else break;
}
return prime;
}
int main(int argc, char **argv)
{
cout << "== BIG PRIME ==" << endl;
for (int i=0; i<10; i++)
{
mpz_class prime(getPrime(2048, true));
cout << prime.get_mpz_t() << endl;
}
return 0;
}