-
Notifications
You must be signed in to change notification settings - Fork 0
/
factor_base.hpp
151 lines (120 loc) · 2.6 KB
/
factor_base.hpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef __GNFS_FACTOR_BASE_HPP__
#define __GNFS_FACTOR_BASE_HPP__
#include <iostream>
#include <fstream>
#include <gnfs.hpp>
#include <polynomial_selection.hpp>
class FactorBase
{
public:
std::vector <int> RFB;
std::vector <int> RFBm;
std::vector <double> RFBlog;
std::vector <int> AFB;
std::vector <int> AFBr;
std::vector <double> AFBlog;
std::vector <int> QCB;
std::vector <int> QCBs;
// {{{ prime_logarithm()
double prime_logarithm(std::vector <int> &FB, int bound, int p, NTL::ZZ n)
{
NTL::ZZ x;
double res=0;
x = n-p;
for(int i=0; i<bound; i++)
{
double l = FB[i];
if(x%FB[i]==0)
res += log(l);
else
return 0;
}
return res;
}
// }}}
// {{{ make_RFB()
void make_RFB(Polynomial &polynomial, Target &target, const char *primes)
{
std::ifstream fin(primes);
int bound = target.t;
//int ext = bound/2;
int ext = 0;
for(int i = 0; i < bound; i++)
{
int p;
double l;
fin >> p;
l = p;
RFB.push_back(p);
RFBm.push_back(polynomial.m % p);
if(i < bound-ext)
l = log(l);
else
l = prime_logarithm(RFB, bound-ext, p, target.n);
RFBlog.push_back(l);
}
fin.close();
}
// }}}
// {{{ make_AFB()
void make_AFB(Polynomial &polynomial, Target &target, const char *primes)
{
int u = 0;
int p;
double l;
int bound = target.t;
//int ext = (d*bound)/2;
int ext = 0;
std::ifstream fin(primes);
NTL::ZZ jZ, pZ;
while(u < polynomial.d * bound)
{
fin >> p;
pZ = p;
int count = 0;
for(int j = 0; j < p && count < polynomial.d; j++)
{
jZ = j;
if(F(polynomial.f, jZ) % pZ == 0)
{
count++;
AFB.push_back(p);
AFBr.push_back(j);
if(u < polynomial.d*bound-ext)
l = log(p);
else
l = prime_logarithm(AFB, bound-ext, p, target.n);
AFBlog.push_back(l);
u++;
}
}
}
fin.close();
}
// }}}
// {{{ make_QFB()
void make_QFB(Target &target, Polynomial &polynomial, int lastp,
const char *primes)
{
int p = lastp;
int v = 0;
NTL::ZZ jZ, pZ;
while(v<target.digits)
{
p = NTL::NextPrime(p+1);
pZ = p;
for(int j = 0; j < p; j++)
{
jZ = j;
if(F(polynomial.f, jZ) % pZ == 0)
{
QCB.push_back(p);
QCBs.push_back(j);
v++;
}
}
}
}
// }}}
};
#endif