You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

25 years ago
  1. #include "test_nt.h"
  2. int test_nt_jacobi (int iterations)
  3. {
  4. int error = 0;
  5. int i;
  6. // Check special cases.
  7. for (i = iterations; i > 0; i--) {
  8. cl_I b = 1+2*abs(testrandom_I());
  9. cl_I c = testrandom_I();
  10. if (b==1) {
  11. ASSERT2(jacobi(b*c,b) == 1, b,c);
  12. } else {
  13. ASSERT2(jacobi(b*c,b) == 0, b,c);
  14. }
  15. }
  16. for (i = iterations; i > 0; i--) {
  17. cl_I b = 1+2*abs(testrandom_I());
  18. if (mod(b,4)==1) {
  19. ASSERT1(jacobi(-1,b) == 1, b);
  20. } else {
  21. ASSERT1(jacobi(-1,b) == -1, b);
  22. }
  23. if (abs(mod(b,8)-4)==1) {
  24. ASSERT1(jacobi(2,b) == -1, b);
  25. } else {
  26. ASSERT1(jacobi(2,b) == 1, b);
  27. }
  28. }
  29. // Check quadratic residues.
  30. for (i = iterations; i > 0; i--) {
  31. cl_I b = 1+2*abs(testrandom_I());
  32. cl_I c = testrandom_I();
  33. cl_I a = mod(square(c),b);
  34. if (gcd(a,b)==1) {
  35. ASSERT2(jacobi(a,b) == 1, b,c);
  36. } else {
  37. ASSERT2(jacobi(a,b) == 0, b,c);
  38. }
  39. }
  40. // Check homomorphism (fixed b).
  41. for (i = iterations; i > 0; i--) {
  42. cl_I b = 1+2*abs(testrandom_I());
  43. cl_I a1 = testrandom_I();
  44. cl_I a2 = testrandom_I();
  45. ASSERT3(jacobi(a1,b)*jacobi(a2,b) == jacobi(a1*a2,b), b,a1,a2);
  46. }
  47. // Check homomorphism (fixed a).
  48. for (i = iterations; i > 0; i--) {
  49. cl_I a = testrandom_I();
  50. cl_I b1 = 1+2*abs(testrandom_I());
  51. cl_I b2 = 1+2*abs(testrandom_I());
  52. ASSERT3(jacobi(a,b1)*jacobi(a,b2) == jacobi(a,b1*b2), a,b1,b2);
  53. }
  54. return error;
  55. }