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.

58 lines
1.6 KiB

25 years ago
  1. #include <cl_number.h>
  2. #include <cl_io.h>
  3. #include <cl_integer.h>
  4. #include <cl_modinteger.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <cl_timing.h>
  8. int main (int argc, char * argv[])
  9. {
  10. int repetitions = 1;
  11. if ((argc >= 3) && !strcmp(argv[1],"-r")) {
  12. repetitions = atoi(argv[2]);
  13. argc -= 2; argv += 2;
  14. }
  15. if (argc < 1)
  16. exit(1);
  17. cl_I p = "1269281897404513557783934075031171555202695168107";
  18. cl_modint_ring R = cl_find_modint_ring(p);
  19. {
  20. cl_MI a = R->canonhom("1111111111111111111111111111111111111111111111111");
  21. cl_MI b = R->canonhom("777777777777777777777777777777777777777777777777");
  22. cl_stdout << "product modulo p" << endl;
  23. { CL_TIMING;
  24. for (int rep = repetitions; rep > 0; rep--)
  25. { cl_MI c = R->mul(a,b); }
  26. }
  27. cl_stdout << "square modulo p" << endl;
  28. { CL_TIMING;
  29. for (int rep = repetitions; rep > 0; rep--)
  30. { cl_MI c = R->square(a); }
  31. }
  32. cl_stdout << "quotient modulo p" << endl;
  33. { CL_TIMING;
  34. for (int rep = repetitions; rep > 0; rep--)
  35. { cl_MI c = R->div(a,b); }
  36. }
  37. }
  38. {
  39. cl_MI a = R->canonhom("1234567890123456789012345678901234567890123456789");
  40. cl_MI b = R->canonhom("909090909090909090909090909090909090909090909090");
  41. cl_stdout << "product modulo p" << endl;
  42. { CL_TIMING;
  43. for (int rep = repetitions; rep > 0; rep--)
  44. { cl_MI c = R->mul(a,b); }
  45. }
  46. cl_stdout << "square modulo p" << endl;
  47. { CL_TIMING;
  48. for (int rep = repetitions; rep > 0; rep--)
  49. { cl_MI c = R->square(a); }
  50. }
  51. cl_stdout << "quotient modulo p" << endl;
  52. { CL_TIMING;
  53. for (int rep = repetitions; rep > 0; rep--)
  54. { cl_MI c = R->div(a,b); }
  55. }
  56. }
  57. }