-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecm-test.cpp
63 lines (50 loc) · 1.4 KB
/
ecm-test.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
58
59
60
61
62
#include <iostream>
#include <time.h>
#include "ZZFactoring.h"
using namespace NTL;
// multiply out factorization to get n
void mul(ZZ& n, const vec_pair_ZZ_long& factorization) {
n=1;
for (long i=0; i<factorization.length(); ++i)
n*=power(factorization[i].a,factorization[i].b);
}
// simple test program for factoring integers using ECM method
int main(int argc, char* argv[]) {
// initialize random number generator
SetSeed(to_ZZ(time(0)));
// number of random integers to factor
long count=16;
// size of integers (in bits)
long bits=128;
// set to true to get more output
bool verbose=false;
ZZ n,nc;
vec_pair_ZZ_long factorization;
double min = HUGE_VAL;
double max = 0;
double start = GetTime();
double prev = start;
double end = start;
// factor count integers
for (long i=0; i<count; ++i) {
RandomBits(n,bits);
std::cout<<"n="<<n<<std::endl;
factor(factorization,n,ZZ::zero(),0,verbose);
std::cout<<factorization<<std::endl;
mul(nc,factorization);
if (n!=nc) {
std::cout<<"check="<<nc<<std::endl;
Error("FAILED FACTORIZATION");
}
std::cout<<std::endl;
end = GetTime();
if (end-prev<min) min=end-prev;
if (end-prev>max) max=end-prev;
prev=end;
}
// display statistics
if (min<0) min=0;
std::cout<<"min="<<min<<" avg="<<((end-start)/count)<<" max="<<max
<<" (seconds)"<<std::endl;
return 0;
}