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>
12 int main (int argc, char * argv[])
15 if ((argc >= 3) && !strcmp(argv[1],"-r")) {
16 repetitions = atoi(argv[2]);
21 cl_I len = cl_I(argv[1]);
22 int e = (argc > 2 ? atoi(argv[2]) : 0);
29 p = ((random_I((cl_I)1 << (len-1-e))*2+1) << e) + 1;
30 } while (!isprobprime(p));
31 cout << "p = " << p << endl;
32 cl_modint_ring R = find_modint_ring(p);
33 cl_MI x = R->random();
37 extern int cl_sqrt_algo;
40 for (int rep = repetitions; rep > 0; rep--)
41 { sol = sqrt_mod_p(R,a); }
44 cerr << "p not prime!" << endl;
46 if (sol.solutions == 0)
47 cerr << "No sqrt found!" << endl;
48 if (!(sol.solution[0] == x || sol.solution[0] == -x))
49 cerr << "Wrong result!" << endl;
53 for (int rep = repetitions; rep > 0; rep--)
54 { sol = sqrt_mod_p(R,a); }
57 cerr << "p not prime!" << endl;
59 if (sol.solutions == 0)
60 cerr << "No sqrt found!" << endl;
61 if (!(sol.solution[0] == x || sol.solution[0] == -x))
62 cerr << "Wrong result!" << endl;
67 for (int rep = repetitions; rep > 0; rep--)
68 { sol = sqrt_mod_p(R,a); }
71 cerr << "p not prime!" << endl;
73 if (sol.solutions == 0)
74 cerr << "No sqrt found!" << endl;
75 if (!(sol.solution[0] == x || sol.solution[0] == -x))
76 cerr << "Wrong result!" << endl;