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>
14 int main (int argc, char * argv[])
17 if ((argc >= 3) && !strcmp(argv[1],"-r")) {
18 repetitions = atoi(argv[2]);
23 cl_I len = cl_I(argv[1]);
24 int e = (argc > 2 ? atoi(argv[2]) : 0);
31 p = ((random_I((cl_I)1 << (len-1-e))*2+1) << e) + 1;
32 } while (!isprobprime(p));
33 cout << "p = " << p << endl;
34 cl_modint_ring R = find_modint_ring(p);
35 cl_MI x = R->random();
39 extern int cl_sqrt_algo;
42 for (int rep = repetitions; rep > 0; rep--)
43 { sol = sqrt_mod_p(R,a); }
46 cerr << "p not prime!" << endl;
48 if (sol.solutions == 0)
49 cerr << "No sqrt found!" << endl;
50 if (!(sol.solution[0] == x || sol.solution[0] == -x))
51 cerr << "Wrong result!" << endl;
55 for (int rep = repetitions; rep > 0; rep--)
56 { sol = sqrt_mod_p(R,a); }
59 cerr << "p not prime!" << endl;
61 if (sol.solutions == 0)
62 cerr << "No sqrt found!" << endl;
63 if (!(sol.solution[0] == x || sol.solution[0] == -x))
64 cerr << "Wrong result!" << endl;
69 for (int rep = repetitions; rep > 0; rep--)
70 { sol = sqrt_mod_p(R,a); }
73 cerr << "p not prime!" << endl;
75 if (sol.solutions == 0)
76 cerr << "No sqrt found!" << endl;
77 if (!(sol.solution[0] == x || sol.solution[0] == -x))
78 cerr << "Wrong result!" << endl;