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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
#include <NTL/ZZ_pXFactoring.h>
#include <NTL/ZZXFactoring.h>
#include <NTL/GF2XFactoring.h>
#include <NTL/GF2EXFactoring.h>
NTL_CLIENT
#define TIME_IT(t, action) \
do { \
double _t0, _t1; \
long _iter = 1; \
long _cnt = 0; \
do { \
_t0 = GetTime(); \
for (long _i = 0; _i < _iter; _i++) { action; _cnt++; } \
_t1 = GetTime(); \
} while ( _t1 - _t0 < 4 && (_iter *= 2)); \
t = (_t1 - _t0)/_iter; \
} while(0)
int main()
{
double t;
long k = 1000;
long n = 1000;
{
SetSeed(conv<ZZ>(1));
ZZ p = RandomPrime_ZZ(k);
ZZ_p::init(p);
ZZ x, y, z, w, s1, s2;
SetSeed(conv<ZZ>(2));
RandomBnd(x, p);
SetSeed(conv<ZZ>(3));
RandomBnd(y, p);
TIME_IT(t, mul(z, x, y));
cout << "multiply 1000-bit ints: " << t << "\n";
TIME_IT(t, sqr(w, x));
cout << "square 1000-bit ints: " << t << "\n";
TIME_IT(t, rem(w, z, p));
cout << "remainder 2000/1000-bit ints: " << t << "\n";
TIME_IT(t, GCD(w, x, y));
cout << "gcd 1000-bit ints: " << t << "\n";
TIME_IT(t, XGCD(w, s1, s2, x, y));
cout << "xgcd 1000-bit ints: " << t << "\n";
TIME_IT(t, PowerMod(w, x, y, p));
cout << "power mod 1000-bit ints: " << t << "\n";
ZZ_pX a, b, c;
SetSeed(conv<ZZ>(4));
random(a, n);
SetSeed(conv<ZZ>(5));
random(b, n);
mul(c, a, b);
TIME_IT(t, mul(c, a, b));
cout << "multiply degree-1000 poly mod 1000-bit prime: " << t << "\n";
ZZ_pX f;
SetSeed(conv<ZZ>(6));
random(f, n);
SetCoeff(f, n);
ZZ_pX A, B;
SetSeed(conv<ZZ>(7));
random(A, 2*(deg(f)-1));
TIME_IT(t, rem(B, A, f));
cout << "remainder degree-2000/1000 poly mod 1000-bit prime: " << t << "\n";
ZZ_pXModulus F(f);
TIME_IT(t, rem(B, A, F));
cout << "preconditioned remainder degree-2000/1000 poly mod 1000-bit prime: " << t << "\n";
TIME_IT(t, GCD(a, b));
cout << "gcd degree-1000 poly mod 1000-bit prime: " << t << "\n";
ZZX AA = conv<ZZX>(a);
ZZX BB = conv<ZZX>(b);
ZZX CC;
TIME_IT(t, mul(CC, AA, BB));
cout << "multiply degree-1000 int poly with 1000-bit coeffs: " << t << "\n";
cout << "\n";
cout << "factoring degree-1000 poly mod 1000-bit prime...\n";
TIME_IT(t, CanZass(f, _cnt == 0));
cout << "...total time = " << t << "\n\n";
}
{
n = 500;
k = 500;
SetSeed(conv<ZZ>(8));
GF2X p = BuildRandomIrred(BuildIrred_GF2X(k));
GF2E::init(p);
GF2X x, y, z, w;
SetSeed(conv<ZZ>(9));
random(x, deg(p));
SetSeed(conv<ZZ>(10));
random(y, deg(p));
TIME_IT(t, mul(z, x, y));
cout << "multiply 500-bit GF2Xs: " << t << "\n";
TIME_IT(t, rem(w, z, p));
cout << "remainder 1000/500-bit GF2Xs: " << t << "\n";
TIME_IT(t, GCD(w, x, y));
cout << "gcd 500-bit GF2Xs: " << t << "\n";
SetSeed(conv<ZZ>(11));
GF2X fff;
random(fff, k);
SetCoeff(fff, k);
cout << "\n";
TIME_IT(t, CanZass(fff, 0));
cout << "factoring degree-500 GF2X: " << t << "\n";
TIME_IT(t, GCD(w, x, y));
cout << "gcd 500-bit GF2X: " << t << "\n";
GF2EX a, b, c;
SetSeed(conv<ZZ>(12));
random(a, n);
SetSeed(conv<ZZ>(13));
random(b, n);
mul(c, a, b);
TIME_IT(t, mul(c, a, b));
cout << "multiply degree-500 poly mod 500-bit GF2X: " << t << "\n";
GF2EX f;
SetSeed(conv<ZZ>(14));
random(f, n);
SetCoeff(f, n);
GF2EX A, B;
SetSeed(conv<ZZ>(15));
random(A, 2*(deg(f)-1));
TIME_IT(t, rem(B, A, f));
cout << "remainder degree-1000/500 poly mod 500-bit GF2X: " << t << "\n";
GF2EXModulus F(f);
TIME_IT(t, rem(B, A, F));
cout << "preconditioned remainder degree-1000/500 poly mod 500-bit GF2X: " << t << "\n";
TIME_IT(t, GCD(a, b));
cout << "gcd degree-500 poly mod 500-bit GF2X: " << t << "\n";
f = f >> n/2;
cout << "\n";
cout << "factoring degree-500 poly mod 500-bit GF2X...\n";
TIME_IT(t, CanZass(f, _cnt == 0));
cout << "\n...total time = " << t << "\n";
}
}
|