1 #include <cln/number.h>
3 #include <cln/integer.h>
4 #include <cln/integer_io.h>
5 #include <cln/modinteger.h>
6 #include <cln/numtheory.h>
9 #include <cln/timing.h>
11 int main (int argc, char * argv[])
14 if ((argc >= 3) && !strcmp(argv[1],"-r")) {
15 repetitions = atoi(argv[2]);
20 cl_I len = cl_I(argv[1]);
21 int e = (argc > 2 ? atoi(argv[2]) : 0);
28 p = ((random_I((cl_I)1 << (len-1-e))*2+1) << e) + 1;
29 } while (!isprobprime(p));
30 cout << "p = " << p << endl;
31 cl_modint_ring R = find_modint_ring(p);
32 cl_MI x = R->random();
36 extern int cl_sqrt_algo;
39 for (int rep = repetitions; rep > 0; rep--)
40 { sol = sqrt_mod_p(R,a); }
43 cerr << "p not prime!" << endl;
45 if (sol.solutions == 0)
46 cerr << "No sqrt found!" << endl;
47 if (!(sol.solution[0] == x || sol.solution[0] == -x))
48 cerr << "Wrong result!" << endl;
52 for (int rep = repetitions; rep > 0; rep--)
53 { sol = sqrt_mod_p(R,a); }
56 cerr << "p not prime!" << endl;
58 if (sol.solutions == 0)
59 cerr << "No sqrt found!" << endl;
60 if (!(sol.solution[0] == x || sol.solution[0] == -x))
61 cerr << "Wrong result!" << endl;
66 for (int rep = repetitions; rep > 0; rep--)
67 { sol = sqrt_mod_p(R,a); }
70 cerr << "p not prime!" << endl;
72 if (sol.solutions == 0)
73 cerr << "No sqrt found!" << endl;
74 if (!(sol.solution[0] == x || sol.solution[0] == -x))
75 cerr << "Wrong result!" << endl;