17namespace layer1_foundations {
18namespace cryptography {
21static double letter_probability[] = {
68 cout <<
"applying key (" << a <<
"," << b <<
")" << endl;
71 for (i = 0; i < l; i++) {
90 int x1, x2, y1, y2, dy, dx, i;
91 int a, b, a0, av, c, g, dxv, n, gg;
94 if (guess.length() != 4) {
95 cout <<
"guess must be 4 characters long!" << endl;
98 cout <<
"guess=" << guess << endl;
104 cout <<
"y1=" << y1 << endl;
105 cout <<
"x1=" << x1 << endl;
106 cout <<
"y2=" << y2 << endl;
107 cout <<
"x2=" << x2 << endl;
108 dy = remainder(y2 - y1, 26);
109 dx = remainder(x2 - x1, 26);
112 cout <<
"solving: a * (x2-x1) = y2 - y1 mod 26" << endl;
113 cout <<
"here: a * " << dx <<
" = " << dy <<
" mod 26" << endl;
117 if (remainder(dy, g) != 0) {
118 cout <<
"gcd(x2-x1,26) does not divide y2-y1, hence no solution! try again" << endl;
125 cout <<
"reducing to: a * " << dx <<
" = " << dy <<
" mod " << n << endl;
128 cout << dx <<
"^-1 mod " << n <<
" = " << dxv << endl;
129 a0 = remainder(dy * dxv, n);
130 cout <<
"solution a = " << a0 <<
" mod " << n << endl;
131 cout <<
"(ie " << g <<
" solutions for a mod 26)" << endl;
132 for (i = 0; i < g; i++) {
133 cout <<
"trying solution " << i + 1 <<
":" << endl;
135 b = remainder(y1 - a * x1, 26);
136 cout <<
"yields key (" << a <<
"," << b <<
")" << endl;
140 cout << a <<
" not prime to 26, no solution" << endl;
144 cout <<
"a^-1 mod 26 = " << av << endl;
146 c = remainder(c, 26);
147 cout <<
"a^-1 (-b) = " << c <<
" mod 26" << endl;
156 int i, j, l, key_len, a, b, c;
159 key_len = key.length();
162 for (i = 0, j = 0; i < l; i++, j++) {
184 int i, j, l, key_len, a, b, c;
187 key_len = key.length();
190 for (i = 0, j = 0; i < l; i++, j++) {
212 int stride, l, n, m, j;
218 cout <<
"key length : Friedman indices in 1/1000-th : average" << endl;
219 for (stride = 1; stride <=
MINIMUM(l, 20); stride++) {
224 cout << stride <<
" : ";
225 for (j = 0; j < stride; j++) {
226 if (j == stride - 1) {
227 n = l - (stride - 1) * m;
235 str2 = ctext.substr(j, n);
244 cout << (int)(1000. * I);
248 II *= 1. / (double) stride;
249 cout <<
" : " << (int)(1000. * II) << endl;
255 int i, j, shift, n, m, l, a, h;
265 for (shift = 0; shift < 26; shift++) {
271 for (j = 0; j < key_length; j++) {
274 if (j == key_length - 1) {
275 n = l - (key_length - 1) * m;
281 std::string str = ctext.substr(j, n);
285 for (shift = 0; shift < 26; shift++) {
288 a = (int)(1000. * I);
291 for (i = 0; i < shift; i++) {
293 for (h = shift; h > i; h--) {
294 index[h] = index[h - 1];
295 shift0[h] = shift0[h - 1];
309 for (i = 0; i < 5; i++) {
314 cout << c <<
" " << index[i];
322 int l, i, j, k, u, h, offset;
323 int *candidates, nb_candidates, *Nb_candidates;
329 candidates =
new int[l];
330 f_taken =
new int[l];
331 Nb_candidates =
new int[l];
332 for (i = 0; i < l; i++) {
336 for (i = 0; i < l; i++) {
339 for (j = i + 1; j < l; j++) {
340 if (ctext[j] == ctext[i]) {
341 candidates[nb_candidates++] = j;
348 Nb_candidates[h - 1] += nb_candidates;
349 while (nb_candidates) {
350 for (k = 0; k < nb_candidates; k++) {
352 if (ctext[i + h] != ctext[j + h]) {
353 for (u = k + 1; u < nb_candidates; u++) {
354 candidates[u - 1] = candidates[u];
361 Nb_candidates[h - 1] += nb_candidates;
362 if (h >= threshold && nb_candidates) {
365 for (k = 0; k < nb_candidates; k++) {
366 offset = candidates[k] - i;
388 for (i = 0; Nb_candidates[i]; i++) {
389 cout <<
"matches of length " << i + 1 <<
" : " << Nb_candidates[i] << endl;
391 delete [] candidates;
393 delete [] Nb_candidates;
398 int i,
int h,
int nb_candidates,
int *candidates)
402 if (nb_candidates == 0) {
405 cout <<
"there are " << nb_candidates <<
" level " << h <<
" coincidences with position " << i << endl;
406 for (k = 0; k < nb_candidates; k++) {
408 cout <<
"at " << j <<
" : ";
409 for (u = 0; u < h; u++) {
410 cout << ctext[i + u];
413 for (u = 0; u < h; u++) {
414 cout << ctext[j + u];
416 cout <<
" offset " << j - i;
425 for (i = 0; i < l; i++) {
433 int i, j, l, l2, lines, line_length;
438 cout <<
"text lengths do not match" << endl;
442 for (i = 0; i <= lines; i++) {
444 line_length = l % 80;
449 for (j = 0; j < line_length; j++) {
450 cout << text1[i * 80 + j];
453 for (j = 0; j < line_length; j++) {
454 cout << text2[i * 80 + j];
464 char str_key[1000], c1, c2;
466 l = guess.length() / 2;
467 for (i = 0; i < 26; i++) {
471 for (i = 0; i < l; i++) {
472 c1 = guess[2 * i + 0];
473 c2 = guess[2 * i + 1];
476 cout << c1 <<
" -> " << c2 << endl;
493 cout <<
"single frequencies:" << endl;
498 cout <<
"double frequencies:" << endl;
505 int i, a = 0, b = n * (n - 1);
508 for (i = 0; i < 26; i++) {
510 a += mult[i] * (mult[i] - 1);
513 d = (double) a / (
double) b;
522 for (i = 0; i < 26; i++) {
526 a += letter_probability[i] * (double) mult[ii];
529 d = (double) a / (
double) n;
535 int i, j = 0, k = 0, h, l = 0, f_first =
TRUE;
538 for (i = 0; i < 26; i++) {
543 int *mult_val =
new int[2 * l];
544 for (i = 0; i < 26; i++) {
546 for (j = 0; j < k; j++) {
547 if (mult_val[2 * j + 1] < mult[i]) {
549 for (h = k; h > j; h--) {
550 mult_val[2 * h + 1] = mult_val[2 * (h - 1) + 1];
551 mult_val[2 * h + 0] = mult_val[2 * (h - 1) + 0];
553 mult_val[2 * j + 0] = i;
554 mult_val[2 * j + 1] = mult[i];
559 mult_val[2 * k + 0] = i;
560 mult_val[2 * k + 1] = mult[i];
566 for (i = 0; i < l; i++) {
567 c =
'a' + mult_val[2 * i + 0];
568 j = mult_val[2 * i + 1];
585 for (i = 0; i < 26; i++) {
588 for (i = 0; i < l; i++) {
589 mult[text[i] -
'a']++;
597 for (i = 0; i < 26; i++) {
600 for (i = 0; i < n; i++) {
601 mult[text[i * stride] -
'a']++;
610 for (i = 0; i < 26; i++) {
613 for (i = 0; i < l - 1; i++) {
614 if (text[i] == text[i + 1]) {
615 mult[text[i] -
'a']++;
626 cout <<
"applying key:" << endl;
627 for (i = 0; i < 26; i++) {
635 for (i = 0; i < l; i++) {
650 if (c >=
'A' && c <=
'Z') {
654 else if (c >=
'a' && c <=
'z') {
666 if (c >=
'a' && c <=
'z') {
670 else if (c >=
'A' && c <=
'Z') {
682 if (c >=
'A' && c <=
'Z') {
685 if (c >=
'a' && c <=
'z') {
697 for (i = 0; i < 26; i++) {
701 for (i = 0; i < 26; i++) {
705 for (k = j + 1; k <= l; k++) {
706 digits[k - 1] = digits[k];
718 int f_v = (verbose_level >= 1);
721 int x0, x, y, len, cnt;
725 cout <<
"make_affine_sequence a=" << a <<
" c=" << c <<
" m=" << m << endl;
731 for (x0 = 0; x0 < m; x0++) {
750 cout <<
"orbit " << cnt <<
" of " << x0 <<
" has length " << len <<
" : ";
766 int *orbit,
int orbit_len,
int cnt,
int m,
int a,
int c,
769 int f_v = (verbose_level >= 1);
772 cout <<
"m=" << m <<
" orbit_len=" << orbit_len << endl;
782 for (h = 0; h < orbit_len - 1; h++) {
791 snprintf(str, 1000,
"orbit_cnt%d_m%d_a%d_c%d.csv", cnt, m, a, c);
795 cout <<
"Written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
807 cout <<
"RAND_MAX=" << RAND_MAX << endl;
809 for (i = 0; i < random_nb; i++) {
823 cout <<
"RAND_MAX=" << RAND_MAX << endl;
826 for (i = 0; i < random_nb; i++) {
834 cout <<
"written file " << fname_csv <<
" of size " << Fio.
file_size(fname_csv) << endl;
840 int EC_b,
int EC_c,
int EC_s,
841 std::string &pt_text, std::string &EC_message,
844 int f_v = (verbose_level >= 1);
848 cout <<
"do_EC_Koblitz_encoding" << endl;
851 cout <<
"do_EC_Koblitz_encoding b = " << EC_b << endl;
852 cout <<
"do_EC_Koblitz_encoding c = " << EC_c << endl;
853 cout <<
"do_EC_Koblitz_encoding s = " << EC_s << endl;
856 vector<vector<int>> Encoding;
863 cout <<
"do_EC_Koblitz_encoding u = " << u << endl;
867 for (i = 1; i <= 26; i++) {
869 for (j = 0; j < u; j++) {
885 Encoding.push_back(pt);
889 cout <<
"failure to encode letter " << i << endl;
893 for (i = 0; i < 26; i++) {
896 x = (i + 1) * u + J[i];
902 cout << (char)(
'A' + i) <<
" & " << i + 1 <<
" & " << J[i] <<
" & " << x
905 <<
" & $(" << Encoding[i][0] <<
"," << Encoding[i][1] <<
")$ "
910 cout <<
"without j:" << endl;
911 for (i = 0; i < 26; i++) {
912 cout << (char)(
'A' + i) <<
" & $(" << Encoding[i][0] <<
"," << Encoding[i][1] <<
")$ \\\\" << endl;
918 vector<vector<int>> Pts;
929 int msRx, msRy, msRz;
936 cout <<
"point should have just two coordinates" << endl;
943 cout <<
"G = (" << Gx <<
"," << Gy <<
"," << Gz <<
")" << endl;
955 minus_s = order - EC_s;
957 cout <<
"order = " << order << endl;
958 cout <<
"minus_s = " << minus_s << endl;
960 Ax = Pts[EC_s - 1][0];
961 Ay = Pts[EC_s - 1][1];
963 cout <<
"A = (" << Ax <<
"," << Ay <<
"," << Az <<
")" << endl;
965 len = EC_message.length();
969 vector<vector<int>> Ciphertext;
971 for (i = 0; i < len; i++) {
972 if (EC_message[i] <
'A' || EC_message[i] >
'Z') {
975 m = EC_message[i] -
'A' + 1;
978 Mx = Encoding[m - 1][0];
979 My = Encoding[m - 1][1];
1012 cipher.push_back(Rx);
1013 cipher.push_back(Ry);
1014 cipher.push_back(Tx);
1015 cipher.push_back(Ty);
1016 Ciphertext.push_back(cipher);
1019 cout << setw(4) << i <<
" & " << EC_message[i] <<
" & " << setw(4) << m <<
" & " << setw(4) << k
1020 <<
"& (" << setw(4) << Mx <<
"," << setw(4) << My <<
"," << setw(4) << Mz <<
") "
1021 <<
"& (" << setw(4) << Rx <<
"," << setw(4) << Ry <<
"," << setw(4) << Rz <<
") "
1022 <<
"& (" << setw(4) << Cx <<
"," << setw(4) << Cy <<
"," << setw(4) << Cz <<
") "
1023 <<
"& (" << setw(4) << Tx <<
"," << setw(4) << Ty <<
"," << setw(4) << Tz <<
") "
1029 cout <<
"Ciphertext:\\\\" << endl;
1030 for (i = 0; i < (int) Ciphertext.size(); i++) {
1031 cout << Ciphertext[i][0] <<
",";
1032 cout << Ciphertext[i][1] <<
",";
1033 cout << Ciphertext[i][2] <<
",";
1034 cout << Ciphertext[i][3] <<
"\\\\" << endl;
1037 for (i = 0; i < (int) Ciphertext.size(); i++) {
1038 Rx = Ciphertext[i][0];
1039 Ry = Ciphertext[i][1];
1040 Tx = Ciphertext[i][2];
1041 Ty = Ciphertext[i][3];
1045 EC_b, EC_c, minus_s,
1060 cout << setw(4) << i <<
" & (" << Rx <<
"," << Ry <<
"," << Tx <<
"," << Ty <<
") "
1061 <<
"& (" << setw(4) << msRx <<
"," << setw(4) << msRy <<
"," << setw(4) << msRz <<
") "
1062 <<
"& (" << setw(4) << Dx <<
"," << setw(4) << Dy <<
"," << setw(4) << Dz <<
") "
1063 <<
" & " << plain <<
" & " << (char)(
'A' - 1 + plain)
1074 cout <<
"cryptography_domain::do_EC_Koblitz_encoding done" << endl;
1079 int EC_b,
int EC_c,
int verbose_level)
1081 int f_v = (verbose_level >= 1);
1082 int x, y, r, y1, y2;
1085 cout <<
"cryptography_domain::do_EC_points" << endl;
1087 vector<vector<int>> Pts;
1089 for (x = 0; x < F->
q; x++) {
1146 l = Legendre(r, q, 0);
1152 if (F->
mult(y, y) != r) {
1153 cout <<
"There is a problem "
1154 "with the square root" << endl;
1163 add_point_to_table(x, y1, 1);
1165 cout <<
"The number of points "
1166 "exceeds the bound" << endl;
1169 add_point_to_table(x, y2, 1);
1171 cout <<
"The number of points "
1172 "exceeds the bound" << endl;
1183 add_point_to_table(x, y, 1);
1185 cout <<
"The number of points exceeds "
1186 "the bound" << endl;
1205 cout <<
"We found " << Pts.size() <<
" points:" << endl;
1208 for (i = 0; i < (int) Pts.size(); i++) {
1209 if (i == (
int) Pts.size()) {
1211 cout << i <<
" : {\\cal O} : 1\\\\" << endl;
1216 vector<vector<int>> Multiples;
1222 Pts[i][0], Pts[i][1], 1,
1228 cout << i <<
" : $(" << Pts[i][0] <<
"," << Pts[i][1] <<
")$ : " << order <<
"\\\\" << endl;
1240 for (i = 0; i < (int) Pts.size(); i++) {
1249 M[(F->
q - 1 - y) * F->
q + x] = 1;
1255 fname.assign(label);
1256 fname.append(
"_points_xy.csv");
1258 cout <<
"Written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
1267 M =
NEW_int((
int) Pts.size() * 2);
1271 for (i = 0; i < (int) Pts.size(); i++) {
1288 fname.assign(label);
1289 fname.append(
"_points_xy_affine_pts.csv");
1291 cout <<
"Written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
1298 cout <<
"cryptography_domain::do_EC_points done" << endl;
1303 int EC_b,
int EC_c,
int x)
1309 x3 = F->
mult(x2, x);
1310 t = F->
add(x3, F->
mult(EC_b, x));
1311 t = F->
add(t, EC_c);
1318 std::string &pt1_text, std::string &pt2_text,
1321 int f_v = (verbose_level >= 1);
1331 cout <<
"do_EC_add" << endl;
1333 vector<vector<int>> Pts;
1337 cout <<
"point should have just two coordinates" << endl;
1347 cout <<
"point should have just two coordinates" << endl;
1362 cout <<
"(" << x1 <<
"," << y1 <<
"," << z1 <<
")";
1364 cout <<
"(" << x2 <<
"," << y2 <<
"," << z2 <<
")";
1366 cout <<
"(" << x3 <<
"," << y3 <<
"," << z3 <<
")";
1373 cout <<
"do_EC_add done" << endl;
1378 int EC_b,
int EC_c, std::string &pt_text,
int verbose_level)
1380 int f_v = (verbose_level >= 1);
1388 cout <<
"cryptography_domain::do_EC_cyclic_subgroup" << endl;
1390 vector<vector<int>> Pts;
1395 cout <<
"cryptography_domain::do_EC_cyclic_subgroup "
1396 "point should have just two coordinates" << endl;
1411 cout <<
"cryptography_domain::do_EC_cyclic_subgroup "
1412 "we found that the point has order " << order << endl;
1413 cout <<
"The multiples are:" << endl;
1414 cout <<
"i : (" << x1 <<
"," << y1 <<
")" << endl;
1415 for (i = 0; i < (int) Pts.size(); i++) {
1417 vector<int> pts = Pts[i];
1419 if (i < (
int) Pts.size() - 1) {
1420 cout << setw(3) << i + 1 <<
" : ";
1421 cout <<
"$(" << pts[0] <<
"," << pts[1] <<
")$";
1422 cout <<
"\\\\" << endl;
1425 cout << setw(3) << i + 1 <<
" : ";
1426 cout <<
"${\\cal O}$";
1427 cout <<
"\\\\" << endl;
1433 cout <<
"cryptography_domain::do_EC_cyclic_subgroup done" << endl;
1438 int EC_b,
int EC_c, std::string &pt_text,
int n,
int verbose_level)
1440 int f_v = (verbose_level >= 1);
1448 cout <<
"cryptography_domain::do_EC_multiple_of" << endl;
1453 cout <<
"cryptography_domain::do_EC_multiple_of "
1454 "point should have just two coordinates" << endl;
1469 cout <<
"The " << n <<
"-fold multiple of (" << x1 <<
"," << y1 <<
") is ";
1475 cout <<
"z1 != 1" << endl;
1478 cout <<
"(" << x3 <<
"," << y3 <<
")" << endl;
1482 cout <<
"cryptography_domain::do_EC_multiple_of done" << endl;
1488 std::string &base_pt_text, std::string &pt_text,
int verbose_level)
1490 int f_v = (verbose_level >= 1);
1499 cout <<
"cryptography_domain::do_EC_discrete_log" << endl;
1504 cout <<
"point should have just two coordinates" << endl;
1519 else if (len == 3) {
1525 cout <<
"the point should have either two or three coordinates" << endl;
1538 cout <<
"The discrete log of (" << x3 <<
"," << y3 <<
"," << z3 <<
") "
1539 "w.r.t. (" << x1 <<
"," << y1 <<
"," << z1 <<
") "
1543 cout <<
"cryptography_domain::do_EC_discrete_log done" << endl;
1548 std::string &EC_bsgs_G,
int EC_bsgs_N,
1549 std::string &EC_bsgs_cipher_text,
1552 int f_v = (verbose_level >= 1);
1564 cout <<
"cryptography_domain::do_EC_baby_step_giant_step" << endl;
1570 cout <<
"point should have just two coordinates" << endl;
1578 n = (int) sqrt((
double) EC_bsgs_N) + 1;
1580 cout <<
"cryptography_domain::do_EC_baby_step_giant_step N = " << EC_bsgs_N << endl;
1581 cout <<
"cryptography_domain::do_EC_baby_step_giant_step n = " << n << endl;
1586 int cipher_text_length = len >> 1;
1590 cout <<
"cryptography_domain::do_EC_baby_step_giant_step "
1591 "cipher_text_length = " << cipher_text_length << endl;
1600 cout <<
"$" << n <<
" * G = (" << nGx <<
"," << nGy <<
")$\\\\" << endl;
1603 for (h = 0; h < cipher_text_length; h++) {
1607 cout <<
" & (" << Cx <<
"," << Cy <<
")";
1611 for (i = 1; i <= n + 1; i++) {
1619 cout << i <<
" & (" << Mx <<
"," << My <<
")";
1621 for (h = 0; h < cipher_text_length; h++) {
1643 cout <<
" & (" << Ax <<
"," << Ay <<
")";
1646 cout <<
"\\\\" << endl;
1654 cout <<
"cryptography_domain::do_EC_baby_step_giant_step done" << endl;
1660 std::string &EC_bsgs_A,
int EC_bsgs_N,
1661 std::string &EC_bsgs_cipher_text, std::string &EC_bsgs_keys,
1664 int f_v = (verbose_level >= 1);
1678 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode" << endl;
1683 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode u = " << u << endl;
1689 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode "
1690 "point should have just two coordinates" << endl;
1701 n = (int) sqrt((
double) EC_bsgs_N) + 1;
1703 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode N = " << EC_bsgs_N << endl;
1704 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode n = " << n << endl;
1709 int cipher_text_length = len >> 1;
1713 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode "
1714 "cipher_text_length = " << cipher_text_length << endl;
1715 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode "
1716 "nb_keys = " << nb_keys << endl;
1718 if (nb_keys != cipher_text_length) {
1719 cout <<
"nb_keys != cipher_text_length" << endl;
1724 for (h = 0; h < cipher_text_length; h++) {
1728 cout << h <<
" & (" << Tx <<
"," << Ty <<
")\\\\" << endl;;
1733 for (h = 0; h < cipher_text_length; h++) {
1743 EC_b, EC_c, keys[h],
1751 cout << h <<
" & " << keys[h]
1752 <<
" & (" << Tx <<
"," << Ty <<
")"
1753 <<
" & (" << Cx <<
"," << Cy <<
")";
1763 cout <<
" & (" << Mx <<
"," << My <<
")";
1766 cout <<
" & " << plain <<
" & " << (char)(
'A' - 1 + plain) <<
"\\\\" << endl;
1775 cout <<
"cryptography_domain::do_EC_baby_step_giant_step_decode done" << endl;
1780 int RSA_block_size, std::string &RSA_encrypt_text,
int verbose_level)
1782 int f_v = (verbose_level >= 1);
1785 cout <<
"cryptography_domain::do_RSA_encrypt_text" << endl;
1788 int i, j, l, nb_blocks;
1793 l = RSA_encrypt_text.length();
1794 nb_blocks = (l + RSA_block_size - 1) / RSA_block_size;
1796 for (i = 0; i < nb_blocks; i++) {
1798 for (j = 0; j < RSA_block_size; j++) {
1799 c = RSA_encrypt_text[i * RSA_block_size + j];
1800 if (c >=
'a' && c <=
'z') {
1802 a += (int) (c -
'a') + 1;
1811 M.
create(RSA_m, __FILE__, __LINE__);
1813 for (i = 0; i < nb_blocks; i++) {
1814 A.
create(Data[i], __FILE__, __LINE__);
1818 if (i < nb_blocks - 1) {
1824 cout <<
"cryptography_domain::do_RSA_encrypt_text done" << endl;
1829 std::string &RSA_text,
int verbose_level)
1831 int f_v = (verbose_level >= 1);
1837 cout <<
"cryptography_domain::do_RSA RSA_d=" << RSA_d <<
" RSA_m=" << RSA_m << endl;
1849 M.
create(RSA_m, __FILE__, __LINE__);
1850 for (i = 0; i < data_sz; i++) {
1851 A.
create(data[i], __FILE__, __LINE__);
1854 cout << i <<
" : " << data[i] <<
" : " << A << endl;
1856 for (i = 0; i < data_sz; i++) {
1857 A.
create(data[i], __FILE__, __LINE__);
1861 if (i < data_sz - 1) {
1871 for (i = 0; i < data_sz; i++) {
1872 A.
create(data[i], __FILE__, __LINE__);
1876 for (j = 0; j < RSA_block_size; j++) {
1878 if (b > 26 || b == 0) {
1879 str[RSA_block_size - 1 - j] =
' ';
1882 str[RSA_block_size - 1 - j] =
'a' + b - 1;
1887 str[RSA_block_size] = 0;
1888 for (j = 0; j < RSA_block_size; j++) {
1889 if (str[j] !=
' ') {
1894 if (i < data_sz - 1) {
1903 std::string &H_coeffs, std::string &R_coeffs, std::string &Msg_coeffs,
1906 int f_v = (verbose_level >= 1);
1909 cout <<
"cryptography_domain::NTRU_encrypt" << endl;
1916 int sz_H, sz_R, sz_Msg;
1932 int dm = sz_Msg - 1;
1937 for (i = 0; i <= dh; i++) {
1938 if (data_H[i] < 0 || data_H[i] >= Fq->
q) {
1939 data_H[i] = NT.
mod(data_H[i], Fq->
q);
1941 FX.
s_i(H, i) = data_H[i];
1946 for (i = 0; i <= dr; i++) {
1947 if (data_R[i] < 0 || data_R[i] >= Fq->
q) {
1948 data_R[i] = NT.
mod(data_R[i], Fq->
q);
1950 FX.
s_i(R, i) = data_R[i];
1955 for (i = 0; i <= dm; i++) {
1956 if (data_Msg[i] < 0 || data_Msg[i] >= Fq->
q) {
1957 data_Msg[i] = NT.
mod(data_Msg[i], Fq->
q);
1959 FX.
s_i(Msg, i) = data_Msg[i];
1963 for (i = 0; i <= N; i++) {
1989 cout <<
"cryptography_domain::NTRU_encrypt before FX.mult_mod" << endl;
1993 FX.
mult_mod(R, H, C, M, verbose_level);
1998 for (i = 0; i <= d; i++) {
2007 cout <<
"cryptography_domain::NTRU_encrypt after FX.mult_mod" << endl;
2014 cout <<
"deg D(X) = " << FX.
degree(D) << endl;
2022 cout <<
"cryptography_domain::NTRU_encrypt done" << endl;
2031 int f_v = (verbose_level >= 1);
2034 cout <<
"cryptography_domain::polynomial_center_lift" << endl;
2056 for (i = 0; i <= da; i++) {
2057 if (data_A[i] < 0 || data_A[i] >= F->
q) {
2058 data_A[i] = NT.
mod(data_A[i], F->
q);
2060 FX.
s_i(A, i) = data_A[i];
2072 cout <<
"cryptography_domain::polynomial_center_lift before FX.mult_mod" << endl;
2081 cout <<
"cryptography_domain::polynomial_center_lift after FX.mult_mod" << endl;
2092 cout <<
"cryptography_domain::polynomial_center_lift done" << endl;
2101 int f_v = (verbose_level >= 1);
2104 cout <<
"cryptography_domain::polynomial_reduce_mod_p" << endl;
2126 for (i = 0; i <= da; i++) {
2127 data_A[i] = NT.
mod(data_A[i], F->
q);
2128 FX.
s_i(A, i) = data_A[i];
2140 cout <<
"cryptography_domain::polynomial_reduce_mod_p done" << endl;
2152 snprintf(fname, 1000,
"jacobi_%d_%d.tex", jacobi_top, jacobi_bottom);
2153 snprintf(title, 1000,
"Jacobi %d over %d", jacobi_top, jacobi_bottom);
2178 A.
create(jacobi_top, __FILE__, __LINE__);
2180 B.
create(jacobi_bottom, __FILE__, __LINE__);
2182 D.
jacobi(A, B, verbose_level);
2185 jacobi_top, jacobi_bottom, verbose_level);
2193 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2204 snprintf(fname, 1000,
"solovay_strassen_%d_%d.tex", p, a);
2205 snprintf(title, 1000,
"Solovay Strassen %d with base %d", p, a);
2230 P.
create(p, __FILE__, __LINE__);
2232 A.
create(a, __FILE__, __LINE__);
2246 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2257 snprintf(fname, 1000,
"miller_rabin_%d.tex", p);
2258 snprintf(title, 1000,
"Miller Rabin %d", p);
2282 P.
create(p, __FILE__, __LINE__);
2286 for (i = 0; i < nb_times; i++) {
2288 f <<
"Miller Rabin test no " << i <<
":\\\\" << endl;
2296 if (i == nb_times) {
2297 f <<
"Miller Rabin: The number is probably prime. Miller Rabin is inconclusive.\\\\" << endl;
2300 f <<
"Miller Rabin: The number is not prime.\\\\" << endl;
2308 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2319 snprintf(fname, 1000,
"fermat_%d.tex", p);
2320 snprintf(title, 1000,
"Fermat test %d", p);
2344 P.
create(p, __FILE__, __LINE__);
2349 f <<
"Fermat: The number $" << P <<
"$ is not prime.\\\\" << endl;
2352 f <<
"Fermat: The number $" << P <<
"$ is probably prime. Fermat test is inconclusive.\\\\" << endl;
2360 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2366 int nb_fermat,
int nb_miller_rabin,
int nb_solovay_strassen,
2373 snprintf(fname, 1000,
"pseudoprime_%d.tex", nb_digits);
2374 snprintf(title, 1000,
"Pseudoprime %d", nb_digits);
2380 ofstream ost(fname);
2401 ost <<
"\\begin{enumerate}[(1)]" << endl;
2408 ost <<
"\\item" << endl;
2409 ost <<
"Trial " << cnt <<
", testing random number " << P << endl;
2411 if (P.
ith(0) != 1 && P.
ith(0) != 3 && P.
ith(0) != 7 && P.
ith(0) != 9) {
2412 ost <<
"the number is not prime by looking at the lowest digit." << endl;
2416 ost <<
"\\begin{enumerate}[(a)]" << endl;
2417 ost <<
"\\item" << endl;
2422 ost <<
"\\end{enumerate}" << endl;
2430 if (nb_miller_rabin) {
2431 ost <<
"\\item" << endl;
2435 ost <<
"Miller Rabin: The number $" << P <<
"$ is not prime.\\\\" << endl;
2436 ost <<
"\\end{enumerate}" << endl;
2444 ost <<
"\\end{enumerate}" << endl;
2448 if (nb_solovay_strassen) {
2449 ost <<
"\\item" << endl;
2451 P, nb_solovay_strassen,
2454 ost <<
"\\end{enumerate}" << endl;
2459 ost <<
"\\end{enumerate}" << endl;
2464 ost <<
"\\end{enumerate}" << endl;
2467 ost <<
"\\end{enumerate}" << endl;
2470 ost <<
"\\end{enumerate}" << endl;
2473 ost <<
"\\noindent" << endl;
2474 ost <<
"The number $" << P <<
"$ is probably prime. \\\\" << endl;
2475 ost <<
"Number of Fermat tests = " << nb_fermat <<
" \\\\" << endl;
2476 ost <<
"Number of Miller Rabin tests = " << nb_miller_rabin <<
" \\\\" << endl;
2477 ost <<
"Number of Solovay-Strassen tests = " << nb_solovay_strassen <<
" \\\\" << endl;
2484 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2495 snprintf(fname, 1000,
"strong_pseudoprime_%d.tex", nb_digits);
2496 snprintf(title, 1000,
"Strong Pseudoprime %d", nb_digits);
2522 f <<
"\\begin{multicols}{2}" << endl;
2523 f <<
"\\begin{enumerate}[(1)]" << endl;
2530 f <<
"\\item" << endl;
2531 f <<
"Trial " << cnt <<
", testing random number " << P << endl;
2533 if (P.
ith(0) != 1 && P.
ith(0) != 3 && P.
ith(0) != 7 && P.
ith(0) != 9) {
2534 f <<
"the number is not prime by looking at the lowest digit" << endl;
2538 f <<
"\\begin{enumerate}[(a)]" << endl;
2539 f <<
"\\item" << endl;
2544 f <<
"\\end{enumerate}" << endl;
2551 f <<
"\\item" << endl;
2556 f <<
"\\end{enumerate}" << endl;
2561 f <<
"\\end{enumerate}" << endl;
2566 f <<
"\\end{enumerate}" << endl;
2569 f <<
"\\end{enumerate}" << endl;
2570 f <<
"\\end{multicols}" << endl;
2572 f <<
"\\noindent" << endl;
2573 f <<
"The number $" << P <<
"$ is probably prime. \\\\" << endl;
2574 f <<
"Number of Fermat tests = " << nb_fermat <<
" \\\\" << endl;
2575 f <<
"Number of Miller Rabin tests = " << nb_miller_rabin <<
" \\\\" << endl;
2582 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2589 int nb_miller_rabin,
int verbose_level)
2595 snprintf(fname, 1000,
"miller_rabin_%s.tex", number_text.c_str());
2596 snprintf(title, 1000,
"Miller Rabin %s", number_text.c_str());
2620 f <<
"\\begin{multicols}{2}" << endl;
2625 if (P.
ith(0) != 1 && P.
ith(0) != 3 && P.
ith(0) != 7 && P.
ith(0) != 9) {
2626 f <<
"the number is not prime by looking at the lowest digit" << endl;
2633 f <<
"Miller Rabin: The number $" << P <<
"$ is not prime.\\\\" << endl;
2636 f <<
"The number $" << P <<
"$ is probably prime. \\\\" << endl;
2641 f <<
"\\end{multicols}" << endl;
2643 f <<
"\\noindent" << endl;
2644 f <<
"Number of Miller Rabin tests = " << nb_miller_rabin <<
" \\\\" << endl;
2651 cout <<
"written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
2657 int factorbase,
int x0,
int verbose_level)
2659 int f_v = (verbose_level >= 1);
2660 vector<int> small_factors, primes, primes_log2, R1, R2;
2664 int f_found_small_factor =
FALSE;
2669 cout <<
"quadratic_sieve" << endl;
2672 cout <<
"quadratic_sieve before sieve" << endl;
2674 NT.
sieve(primes, factorbase, verbose_level - 1);
2676 cout <<
"quadratic_sieve after sieve" << endl;
2677 cout <<
"list of primes has length " << primes.size() << endl;
2680 cout <<
"Mersenne number M_" << n <<
"=" << M <<
" log10=" << M.
len() << endl;
2682 cout <<
"sqrtM=" << sqrtM <<
" log10=" << sqrtM.
len() << endl;
2694 cout <<
"calling reduce_primes" << endl;
2699 f_found_small_factor, small_factor,
2701 if (!f_found_small_factor) {
2706 cout <<
"dividing out small factor " << small_factor << endl;
2707 small_factors.push_back(small_factor);
2708 P.
create(small_factor, __FILE__, __LINE__);
2711 cout <<
"reduced M=" << M <<
" log10=" << M.
len() << endl;
2713 cout <<
"sqrtM=" << sqrtM << endl << endl;
2715 cout <<
"list of small factors has length " << small_factors.size() << endl;
2716 for (i = 0; i < (int) small_factors.size(); i++) {
2717 cout << i <<
" : " << small_factors[i] << endl;
2721 cout <<
"the number has been completely factored" << endl;
2730 int f_x_file =
FALSE;
2735 int l = primes.size();
2738 read_x_file(X, x_file, ll);
2744 primes, primes_log2, R1, R2, X, verbose_level - 1);
2752 cout <<
"quadratic_sieve done" << endl;
2762 for (i = 0; i < l; i++) {
2763 k =
log2(primes[i]);
2764 primes_log2.push_back(k);
2769 std::string &square_root_mod_n,
2770 std::vector<long int> &S,
int verbose_level)
2772 int f_v = (verbose_level >= 1);
2777 cout <<
"cryptography_domain::all_square_roots_mod_n_by_exhaustive_search_lint" << endl;
2780 a = ST.
strtoi(square_root_a);
2781 n = ST.
strtoi(square_root_mod_n);
2782 for (i = 0; i < a; i++) {
2783 if (((i * i) % n) == a) {
2789 cout <<
"cryptography_domain::all_square_roots_mod_n_by_exhaustive_search_lint done" << endl;
2795 int f_v = (verbose_level >= 1);
2800 cout <<
"square_root" << endl;
2803 cout <<
"computing square root of " << a << endl;
2805 cout <<
"square root of " << a <<
" is " << b << endl;
2808 cout <<
"square_root done" << endl;
2813 std::string &mod_number,
int verbose_level)
2815 int f_v = (verbose_level >= 1);
2821 cout <<
"square_root" << endl;
2824 cout <<
"computing square root of " << a << endl;
2826 cout <<
"modulo " << m << endl;
2828 cout <<
"square root of " << a <<
" mod " << m <<
" is " << b << endl;
2831 cout <<
"square_root done" << endl;
2837 int &f_found_small_factor,
int &small_factor,
2840 int f_v = (verbose_level >= 1);
2846 cout <<
"reduce_primes" << endl;
2848 f_found_small_factor =
FALSE;
2851 for (i = 0; i < l; i++) {
2857 R.
create(r, __FILE__, __LINE__);
2858 P.
create(p, __FILE__, __LINE__);
2865 cout <<
"M is divisible by " << p << endl;
2867 f_found_small_factor =
TRUE;
2872 primes.erase(primes.begin()+i);
2877 cout <<
"number of primes remaining = " << primes.size() << endl;
2882 int sift_smooth_len,
2883 std::string &sift_smooth_factor_base,
int verbose_level)
2885 int f_v = (verbose_level >= 1);
2888 int a, i, j, nb, p, idx, cnt;
2893 cout <<
"do_sift_smooth" << endl;
2900 for (i = 0; i < sift_smooth_len; i++) {
2901 a = sift_smooth_from + i;
2907 for (j = 0; j < nb; j++) {
2916 cout << cnt <<
" : " << a <<
" : ";
2931 int f_v = (verbose_level >= 1);
2937 cout <<
"do_discrete_log" << endl;
2938 cout <<
"y=" << y << endl;
2939 cout <<
"a=" << a << endl;
2940 cout <<
"p=" << p << endl;
2948 for (n = 0; n < p - 1; n++) {
2957 cout <<
"could not solve the discrete log problem." << endl;
2960 cout <<
"The discrete log is " << n <<
" since ";
2961 cout << y <<
" = " << a <<
"^" << n <<
" mod " << p << endl;
2981 cout <<
"a primitive root modulo " << p <<
" is " << a << endl;
3001 cout <<
"a primitive root modulo " << p <<
" is " << a << endl;
3014 int f_v = (verbose_level >= 1);
3022 cout <<
"cryptography_domain::do_smallest_primitive_root p=" << p << endl;
3027 cout <<
"a primitive root modulo " << p <<
" is " << a << endl;
3035 cout <<
"cryptography_domain::do_smallest_primitive_root done" << endl;
3041 int f_v = (verbose_level >= 1);
3052 cout <<
"cryptography_domain::do_smallest_primitive_root_interval p_min=" << p_min <<
" p_max=" << p_max << endl;
3055 std::vector<std::pair<long int, long int>> Table;
3057 for (p = p_min; p < p_max; p++) {
3063 std::pair<long int, long int> P;
3066 cout <<
"a primitive root modulo " << p <<
" is " << a << endl;
3075 for (i = 0; i < Table.size(); i++) {
3076 T[2 * i + 0] = Table[i].first;
3077 T[2 * i + 1] = Table[i].second;
3079 sprintf(str,
"primitive_element_table_%ld_%ld.csv", p_min, p_max);
3085 cout <<
"Written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
3095 cout <<
"cryptography_domain::do_smallest_primitive_root_interval done" << endl;
3101 int f_v = (verbose_level >= 1);
3112 cout <<
"cryptography_domain::do_number_of_primitive_roots_interval p_min=" << p_min <<
" p_max=" << p_max << endl;
3115 std::vector<std::pair<long int, long int>> Table;
3117 for (p = p_min; p < p_max; p++) {
3123 std::pair<long int, long int> P;
3126 cout <<
"the number of primitive elements modulo " << p <<
" is " << a << endl;
3135 for (i = 0; i < Table.size(); i++) {
3136 T[2 * i + 0] = Table[i].first;
3137 T[2 * i + 1] = Table[i].second;
3139 sprintf(str,
"table_number_of_pe_%ld_%ld.csv", p_min, p_max);
3145 cout <<
"Written file " << fname <<
" of size " << Fio.
file_size(fname) << endl;
3155 cout <<
"cryptography_domain::do_number_of_primitive_roots_interval done" << endl;
3170 cout <<
"the inverse of " << a <<
" mod " << n <<
" is " << b << endl;
3186 A.
create(a, __FILE__, __LINE__);
3187 B.
create(b, __FILE__, __LINE__);
3189 cout <<
"before D.extended_gcd" << endl;
3191 G, U, V, verbose_level);
3192 cout <<
"after D.extended_gcd" << endl;
3214 cout <<
"the power of " << a <<
" to the " << k <<
" mod " << n <<
" is " << b << endl;
3226 vector<int> &primes, vector<int> &R1, vector<int> &R2,
3242 int f_v = (verbose_level >= 1);
3243 int i, l, p, Mmodp, sqrtMmodp, b;
3244 int r1, r2, c, c2, s;
3249 cout <<
"cryptography_domain::calc_roots, verbose_level=" << verbose_level << endl;
3250 cout <<
"cryptography_domain::calc_roots, M=" << M << endl;
3251 cout <<
"cryptography_domain::calc_roots, sqrtM=" << sqrtM << endl;
3254 for (i = 0; i < l; i++) {
3257 cout <<
"cryptography_domain::calc_roots i=" << i <<
" / " << l <<
" p=" << p << endl;
3259 P.
create(p, __FILE__, __LINE__);
3262 cout <<
"cryptography_domain::calc_roots before remainder_mod_int" << endl;
3266 cout <<
"cryptography_domain::calc_roots after remainder_mod_int "
3267 "Mmodp=" << Mmodp << endl;
3270 cout <<
"cryptography_domain::calc_roots before remainder_mod_int" << endl;
3274 cout <<
"cryptography_domain::calc_roots after remainder_mod_int, "
3275 "sqrtMmodp=" << sqrtMmodp << endl;
3282 l1.
create(sqrtMmodp, __FILE__, __LINE__);
3297 l1.
create(sqrtMmodp, __FILE__, __LINE__);
3308 cout <<
"cryptography_domain::calc_roots computing square root "
3309 "of discriminant c2=" << c2 << endl;
3313 cout <<
"cryptography_domain::calc_roots c2=" << c2 <<
" s=" << s << endl;
3332 cout <<
"cryptography_domain::calc_roots r1=" << r1 <<
" r2=" << r2 << endl;
3344 cout <<
"cryptography_domain::calc_roots done" << endl;
3350 int f_mod,
int mod_n,
int mod_r,
int x0,
3352 std::vector<int> &primes, std::vector<int> &primes_log2,
3353 std::vector<int> &R1, std::vector<int> &R2,
3354 std::vector<int> &X,
3357 int f_v = (verbose_level >= 1);
3362 cout <<
"cryptography_domain::Quadratic_Sieve" << endl;
3364 ff <<
"X_M_" << n <<
"_FB_" << factorbase;
3366 ff <<
"_mod_" << mod_n <<
"_" << mod_r;
3372 int l = primes.size();
3374 int from = x0, to = x0, count = -1, step_size = 50000;
3377 ll = ll / mod_n + 1;
3386 to = from + step_size;
3390 if (count % mod_n != mod_r) {
3395 primes, primes_log2, R1, R2, from, to, ll, X, verbose_level)) {
3401 cout <<
"found " << ll <<
" x_i" << endl;
3405 ofstream f(s.c_str());
3410 for (i = 0; i < ll; i++) {
3412 if ((i + 1) % 10 == 0)
3416 f << endl <<
"-1" << endl;
3422 std::vector<int> &primes, std::vector<int> &primes_log2,
3423 std::vector<int> &R1, std::vector<int> &R2,
3425 int ll, std::vector<int> &X,
3428 int f_v = (verbose_level >= 1);
3433 vector<int> factor_idx, factor_exp;
3436 cout <<
"cryptography_domain::quadratic_sieve" << endl;
3438 zero.
create(0, __FILE__, __LINE__);
3442 cout <<
"quadratic sieve from=" << from
3443 <<
" to=" << to <<
" j=" << j << endl;
3444 cout <<
"searching for " << ll <<
" numbers" << endl;
3446 for (x = from; x < to; x++) {
3449 a.
create(x, __FILE__, __LINE__);
3463 int xmodp, log2a, sumlog2;
3464 log2a = 3 * (a.
len() - 1);
3466 for (i = 0; i < l; i++) {
3467 xmodp = x % primes[i];
3468 if (xmodp == R1[i]) {
3469 sumlog2 += primes_log2[i] + 0;
3471 if (xmodp == R2[i]) {
3472 sumlog2 += primes_log2[i] + 0;
3477 if (sumlog2 < log2a)
3481 primes, factor_idx, factor_exp,
3482 verbose_level - 1)) {
3487 cout <<
"found solution " << j <<
" which is " << x
3488 <<
", need " << ll - j <<
" more" << endl;
3494 cout <<
"sieve: found enough numbers "
3495 "(enough = " << ll <<
")" << endl;
3498 cout <<
"cryptography_domain::quadratic_sieve done" << endl;
3504 cout <<
"cryptography_domain::quadratic_sieve done" << endl;
3510 std::vector<int> &primes,
3511 std::vector<int> &factor_idx, std::vector<int> &factor_exp,
3519 z1.
create(1, __FILE__, __LINE__);
3523 for (i = 0; i < l; i++) {
3531 factor_idx.push_back(i);
3532 factor_exp.push_back(n);
3545 vector<int> &primes, vector<int> &exponents,
3553 z1.
create(1, __FILE__, __LINE__);
3555 for (i = 0; i < l; i++) {
3565 nn = exponents[i] + n;
3580 int nb_solovay_strassen_tests,
int f_miller_rabin_test,
3583 int f_v = (verbose_level >= 1);
3584 int f_vv = (verbose_level >= 2);
3590 cout <<
"cryptography_domain::find_probable_prime_above" << endl;
3592 one.
create(1, __FILE__, __LINE__);
3595 cout <<
"considering " << a << endl;
3599 cout <<
"is not prime because of Miller Rabin" << endl;
3604 nb_solovay_strassen_tests, verbose_level - 2)) {
3606 cout <<
"may be prime" << endl;
3612 cout <<
"is not prime because of "
3613 "Solovay Strassen" << endl;
3622 cout <<
"cryptography_domain::find_probable_prime_above: probable prime: "
3623 << a <<
" (found after " << i <<
" tests)" << endl;
3630 int f_v = (verbose_level >= 1);
3634 cout <<
"cryptography_domain::solovay_strassen_is_prime for "
3635 << n <<
" with " << nb_tests <<
" tests:" << endl;
3637 for (i = 0; i < nb_tests; i++) {
3639 n, verbose_level - 2)) {
3641 cout <<
"is not prime after "
3642 << i + 1 <<
" tests" << endl;
3653 int f_v = (verbose_level >= 1);
3654 int f_vv = (verbose_level >= 2);
3660 cout <<
"cryptography_domain::solovay_strassen_is_prime_single_test" << endl;
3662 one.
create(1, __FILE__, __LINE__);
3663 m_one.
create(-1, __FILE__, __LINE__);
3664 D.
add(n, m_one, n_minus_one);
3669 cout <<
"cryptography_domain::solovay_strassen_is_prime "
3670 "choosing integer " << a
3671 <<
" less than " << n << endl;
3684 int f_v = (verbose_level >= 1);
3690 cout <<
"cryptography_domain::fermat_test_iterated_with_latex_key" << endl;
3692 one.
create(1, __FILE__, __LINE__);
3693 minus_two.
create(-2, __FILE__, __LINE__);
3695 D.
add(P, minus_two, n_minus_two);
3697 ost <<
"We will do " << nb_times <<
" Fermat tests for $" << P <<
"$:\\\\" << endl;
3699 ost <<
"\\begin{enumerate}[(1)]" << endl;
3700 for (i = 0; i < nb_times; i++) {
3703 ost <<
"\\item" << endl;
3704 ost <<
"Fermat test no " << i + 1 <<
":\\\\" << endl;
3712 ost <<
"Choosing base $" << A <<
".$\\\\" << endl;
3722 ost <<
"\\end{enumerate}" << endl;
3723 if (i == nb_times) {
3732 cout <<
"cryptography_domain::fermat_test_iterated_with_latex_key done" << endl;
3741 int f_v = (verbose_level >= 1);
3742 int f_vv = (verbose_level >= 2);
3747 cout <<
"cryptography_domain::fermat_test_with_latex_key" << endl;
3749 one.
create(1, __FILE__, __LINE__);
3750 m_one.
create(-1, __FILE__, __LINE__);
3751 D.
add(n, m_one, n_minus_one);
3753 cout <<
"cryptography_domain::fermat_test_with_latex_key "
3754 "a = " << a << endl;
3756 ost <<
"Fermat test for $n=" << n <<
",$ picking basis $a=" << a <<
"$\\\\" << endl;
3759 cout <<
"cryptography_domain::fermat_test_with_latex_key "
3760 "a^((n-1)) = " << a << endl;
3762 ost <<
"$a^{" << n_minus_one <<
"} \\equiv " << a <<
"$\\\\" << endl;
3765 cout <<
"cryptography_domain::fermat_test_with_latex_key "
3766 "inconclusive" << endl;
3768 ost <<
"The Fermat test is inconclusive.\\\\" << endl;
3773 cout <<
"cryptography_domain::fermat_test_with_latex_key "
3774 "not prime (sure)" << endl;
3776 ost <<
"The number $" << n <<
"$ is not prime because of the Fermat test.\\\\" << endl;
3785 int f_v = (verbose_level >= 1);
3786 int f_vv = (verbose_level >= 2);
3792 cout <<
"cryptography_domain::solovay_strassen_test" << endl;
3794 one.
create(1, __FILE__, __LINE__);
3795 m_one.
create(-1, __FILE__, __LINE__);
3796 D.
add(n, m_one, n_minus_one);
3798 cout <<
"cryptography_domain::solovay_strassen_test "
3799 "a = " << a << endl;
3801 x = D.
jacobi(a, n, verbose_level - 2);
3804 cout <<
"not prime (sure)" << endl;
3811 cout <<
"cryptography_domain::solovay_strassen_test "
3812 "raising to the power " << n2 << endl;
3816 cout <<
"cryptography_domain::solovay_strassen_test "
3817 "a^((n-1)/2) = " << a << endl;
3822 cout <<
"cryptography_domain::solovay_strassen_test "
3823 "inconclusive" << endl;
3829 cout <<
"cryptography_domain::solovay_strassen_test "
3830 "not prime (sure)" << endl;
3838 cout <<
"cryptography_domain::solovay_strassen_test "
3839 "inconclusive" << endl;
3845 cout <<
"cryptography_domain::solovay_strassen_test "
3846 "not prime (sure)" << endl;
3852 cout <<
"cryptography_domain::solovay_strassen_test "
3861 int f_v = (verbose_level >= 1);
3862 int f_vv = (verbose_level >= 2);
3868 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key" << endl;
3870 one.
create(1, __FILE__, __LINE__);
3871 m_one.
create(-1, __FILE__, __LINE__);
3872 D.
add(n, m_one, n_minus_one);
3874 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3875 "a = " << a << endl;
3877 ost <<
"Solovay-Strassen pseudoprime test for $n=" << n
3878 <<
",$ picking basis $a=" << a <<
"$\\\\" << endl;
3879 x = D.
jacobi(a, n, verbose_level - 2);
3880 ost <<
"$\\Big( \\frac{" << a
3881 <<
" }{ " << n <<
"}\\Big) = " << x <<
"$\\\\" << endl;
3884 cout <<
"not prime (sure)" << endl;
3891 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3892 "raising to the power " << n2 << endl;
3896 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3897 "a^((n-1)/2) = " << a << endl;
3901 ost <<
"$a^{\\frac{" << n <<
"-1}{2}} \\equiv " << a;
3903 ost <<
" \\equiv -1";
3905 ost <<
"$\\\\" << endl;
3910 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3911 "inconclusive" << endl;
3913 ost <<
"The Solovay-Strassen test is inconclusive.\\\\" << endl;
3918 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3919 "not prime (sure)" << endl;
3921 ost <<
"The number $n$ is not prime by the Solovay-Strassen test.\\\\" << endl;
3928 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3929 "inconclusive" << endl;
3931 ost <<
"The Solovay-Strassen test is inconclusive.\\\\" << endl;
3936 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3937 "not prime (sure)" << endl;
3939 ost <<
"The number $n$ is not prime by the Solovay-Strassen test.\\\\" << endl;
3944 cout <<
"cryptography_domain::solovay_strassen_test_with_latex_key "
3954 int f_v = (verbose_level >= 1);
3961 cout <<
"cryptography_domain::solovay_strassen_test_iterated_with_latex_key" << endl;
3964 ost <<
"We will do " << nb_times <<
" Solovay-Strassen "
3965 "tests for $" << P <<
"$:\\\\" << endl;
3967 one.
create(1, __FILE__, __LINE__);
3968 m_one.
create(-1, __FILE__, __LINE__);
3969 m_two.
create(-2, __FILE__, __LINE__);
3970 D.
add(P, m_one, P_minus_one);
3971 D.
add(P, m_two, P_minus_two);
3973 ost <<
"\\begin{enumerate}[(1)]" << endl;
3976 for (i = 0; i < nb_times; i++) {
3979 ost <<
"\\item" << endl;
3980 ost <<
"Solovay-Strassen test no " << i + 1 <<
":\\\\" << endl;
3988 ost <<
"Choosing base $" << A <<
".$\\\\" << endl;
3998 ost <<
"\\end{enumerate}" << endl;
4000 if (i == nb_times) {
4009 cout <<
"cryptography_domain::solovay_strassen_test_iterated_with_latex_key done" << endl;
4020 int f_v = (verbose_level >= 1);
4021 int f_vv = (verbose_level >= 2);
4027 cout <<
"cryptography_domain::miller_rabin_test "
4028 "for " << n << endl;
4030 one.
create(1, __FILE__, __LINE__);
4031 m_one.
create(-1, __FILE__, __LINE__);
4032 D.
add(n, m_one, n_minus_one);
4040 a.
create(2, __FILE__, __LINE__);
4043 cout <<
"cryptography_domain::miller_rabin_test "
4044 "choosing integer " << a <<
" less than " << n << endl;
4050 cout << n_minus_one <<
" = 2^" << k <<
" x " << m << endl;
4057 cout << a <<
"^" << mm <<
" = " << b << endl;
4061 cout <<
"a^m = 1 mod n, so the test is inconclusive" << endl;
4067 cout <<
"is minus one, so the test is inconclusive" << endl;
4071 for (i = 0; i < k; i++) {
4074 cout <<
"b_" << i <<
"=" << b
4075 <<
" b_" << i + 1 <<
"=" << c << endl;
4080 cout <<
"is minus one, so the test is inconclusive" << endl;
4086 cout <<
"is one, we reject as composite" << endl;
4093 cout <<
"inconclusive, we accept as probably prime" << endl;
4101 int f_v = (verbose_level >= 1);
4102 int f_vv = (verbose_level >= 2);
4108 cout <<
"cryptography_domain::miller_rabin_test_with_latex_key "
4109 "for " << n <<
" iteration=" << iteration << endl;
4111 ost <<
"Miller-Rabin pseudoprime test for $n=" << n <<
"$\\\\" << endl;
4112 one.
create(1, __FILE__, __LINE__);
4113 m_one.
create(-1, __FILE__, __LINE__);
4114 D.
add(n, m_one, n_minus_one);
4118 if (iteration < 5) {
4123 a.
create(small_prime, __FILE__, __LINE__);
4134 cout <<
"cryptography_domain::miller_rabin_test_with_latex_key "
4135 "choosing test base a= " << a << endl;
4138 ost <<
"Picking test base $a=" << a <<
"$\\\\" << endl;
4145 cout << a <<
"^{n-1} = " << b << endl;
4148 ost <<
"$a^{n-1} = a^{" << n_minus_one <<
"}=" << b <<
"$\\\\" << endl;
4152 cout <<
"a^{n-1} != 1 mod n, so the number is not prime by Fermat" << endl;
4154 ost <<
"The number is not prime, a=" << a <<
" is a Fermat witness\\\\" << endl;
4158 ost <<
"The number survives the Fermat test\\\\" << endl;
4166 cout << n_minus_one <<
" = 2^" << k <<
" x " << m << endl;
4168 ost <<
"$n-1=2^s \\cdot m = 2^{" << k <<
"} \\cdot " << m <<
"$\\\\" << endl;
4176 cout << a <<
"^" << mm <<
" = " << b << endl;
4179 ost <<
"$b_0 = a^m = a^{" << mm <<
"}=" << b <<
"$\\\\" << endl;
4183 cout <<
"a^m = 1 mod n, so the test is inconclusive" << endl;
4185 ost <<
"The Miller-Rabin test is inconclusive\\\\" << endl;
4190 cout <<
"is minus one, so the test is inconclusive" << endl;
4192 ost <<
"The Miller-Rabin test is inconclusive\\\\" << endl;
4195 ost <<
"$b_{0} = " << b <<
"$\\\\" << endl;
4196 for (i = 0; i < k; i++) {
4199 cout <<
"b_" << i <<
"=" << b
4200 <<
" b_" << i + 1 <<
"=" << c << endl;
4202 ost <<
"$b_{" << i + 1 <<
"} = " << c <<
"$\\\\" << endl;
4206 cout <<
"is minus one, so the test is inconclusive" << endl;
4208 ost <<
"The Miller-Rabin test is inconclusive.\\\\" << endl;
4213 cout <<
"is one, we reject as composite" << endl;
4215 ost <<
"The number is not prime because of the Miller-Rabin test.\\\\" << endl;
4221 cout <<
"inconclusive, we accept as probably prime" << endl;
4223 ost <<
"The Miller-Rabin test is inconclusive.\\\\" << endl;
4226 cout <<
"cryptography_domain::miller_rabin_test_with_latex_key "
4237 int f_v = (verbose_level >= 1);
4241 cout <<
"cryptography_domain::miller_rabin_test_iterated_with_latex_key" << endl;
4244 ost <<
"Miller-Rabin test for $" << P <<
"$:\\\\" << endl;
4246 ost <<
"\\begin{enumerate}[(1)]" << endl;
4247 for (i = 0; i < nb_times; i++) {
4250 ost <<
"\\item" << endl;
4251 ost <<
"Miller-Rabin test no " << i + 1 <<
":\\\\" << endl;
4261 ost <<
"\\end{enumerate}" << endl;
4262 if (i == nb_times) {
4271 cout <<
"cryptography_domain::miller_rabin_test_iterated_with_latex_key done" << endl;
4278 int nb_tests_solovay_strassen,
4279 int f_miller_rabin_test,
int verbose_level)
4281 int f_v = (verbose_level >= 1);
4283 int kk = (k * 3) / 10;
4287 cout <<
"cryptography_domain::get_k_bit_random_pseudoprime "
4288 "trying to get a " << k <<
" bit, " << kk
4289 <<
" decimals random pseudoprime" << endl;
4291 a.
create(10, __FILE__, __LINE__);
4295 cout <<
"choosing integer " << b <<
" less than " << a << endl;
4299 cout <<
"the sum is " << n << endl;
4303 nb_tests_solovay_strassen, f_miller_rabin_test,
4313 int nb_tests_solovay_strassen,
int f_miller_rabin_test,
4316 int f_v = (verbose_level >= 1);
4317 int f_vv = (verbose_level >= 2);
4320 int half_bits = nb_bits >> 1;
4323 cout <<
"cryptography_domain::RSA_setup nb_bits=" << nb_bits
4324 <<
" nb_tests_solovay_strassen=" << nb_tests_solovay_strassen
4325 <<
" f_miller_rabin_test=" << f_miller_rabin_test << endl;
4327 m1.
create(-1, __FILE__, __LINE__);
4329 nb_tests_solovay_strassen,
4330 f_miller_rabin_test, verbose_level - 2);
4332 cout <<
"choosing p = " << p << endl;
4335 nb_tests_solovay_strassen,
4336 f_miller_rabin_test, verbose_level - 2);
4338 cout <<
"choosing p = " << p << endl;
4339 cout <<
"choosing q = " << q << endl;
4343 cout <<
"n = pq = " << n << endl;
4347 D.
mult(pm1, qm1, phi_n);
4349 cout <<
"phi(n) = (p - 1)(q - 1) = "
4356 cout <<
"choosing integer " << a
4357 <<
" less than " << n << endl;
4364 cout <<
"non trivial gcd: " << g
4365 <<
" , repeating" << endl;
4370 cout <<
"making b positive" << endl;
4376 cout <<
"the public key is (a,n) = " << a <<
"," << n << endl;
4377 cout <<
"the private key is (b,n) = " << b <<
"," << n << endl;
void single_frequencies2(std::string &text, int stride, int n, int *mult)
void do_miller_rabin_text(std::string &number_text, int nb_miller_rabin, int verbose_level)
double friedman_index_shifted(int *mult, int n, int shift)
void print_on_top(std::string &text1, std::string &text2)
void do_jacobi(int jacobi_top, int jacobi_bottom, int verbose_level)
void vigenere_cipher(std::string &ptext, std::string &ctext, std::string &key)
void do_EC_discrete_log(field_theory::finite_field *F, int EC_b, int EC_c, std::string &base_pt_text, std::string &pt_text, int verbose_level)
int kasiski_test(std::string &ctext, int threshold)
void do_sift_smooth(int sift_smooth_from, int sift_smooth_len, std::string &sift_smooth_factor_base, int verbose_level)
void do_find_strong_pseudoprime(int nb_digits, int nb_fermat, int nb_miller_rabin, int verbose_level)
void do_EC_Koblitz_encoding(field_theory::finite_field *F, int EC_b, int EC_c, int EC_s, std::string &pt_text, std::string &EC_message, int verbose_level)
int miller_rabin_test(ring_theory::longinteger_object &n, int verbose_level)
void do_discrete_log(long int y, long int a, long int p, int verbose_level)
void do_fermat_test(int p, int nb_times, int verbose_level)
void print_frequencies(int *mult)
void make_affine_sequence(int a, int c, int m, int verbose_level)
void do_EC_baby_step_giant_step(field_theory::finite_field *F, int EC_b, int EC_c, std::string &EC_bsgs_G, int EC_bsgs_N, std::string &EC_bsgs_cipher_text, int verbose_level)
void do_random_last(int random_nb, int verbose_level)
void all_square_roots_mod_n_by_exhaustive_search_lint(std::string &square_root_a, std::string &square_root_mod_n, std::vector< long int > &S, int verbose_level)
void NTRU_encrypt(int N, int p, field_theory::finite_field *Fq, std::string &H_coeffs, std::string &R_coeffs, std::string &Msg_coeffs, int verbose_level)
void do_RSA(long int RSA_d, long int RSA_m, int RSA_block_size, std::string &RSA_text, int verbose_level)
void decipher(std::string &ctext, std::string &ptext, std::string &guess)
void do_EC_cyclic_subgroup(field_theory::finite_field *F, int EC_b, int EC_c, std::string &pt_text, int verbose_level)
int factor_over_factor_base2(ring_theory::longinteger_object &x, std::vector< int > &primes, std::vector< int > &exponents, int verbose_level)
int solovay_strassen_is_prime_single_test(ring_theory::longinteger_object &n, int verbose_level)
void do_random(int random_nb, std::string &fname_csv, int verbose_level)
void do_power_mod(ring_theory::longinteger_object &a, ring_theory::longinteger_object &k, ring_theory::longinteger_object &n, int verbose_level)
void reduce_primes(std::vector< int > &primes, ring_theory::longinteger_object &M, int &f_found_small_factor, int &small_factor, int verbose_level)
void get_random_permutation(std::string &p)
void substition_cipher(std::string &ptext, std::string &ctext, std::string &key)
void RSA_setup(ring_theory::longinteger_object &n, ring_theory::longinteger_object &p, ring_theory::longinteger_object &q, ring_theory::longinteger_object &a, ring_theory::longinteger_object &b, int nb_bits, int nb_tests_solovay_strassen, int f_miller_rabin_test, int verbose_level)
void find_probable_prime_above(ring_theory::longinteger_object &a, int nb_solovay_strassen_tests, int f_miller_rabin_test, int verbose_level)
void Quadratic_Sieve(int factorbase, int f_mod, int mod_n, int mod_r, int x0, int n, ring_theory::longinteger_object &M, ring_theory::longinteger_object &sqrtM, std::vector< int > &primes, std::vector< int > &primes_log2, std::vector< int > &R1, std::vector< int > &R2, std::vector< int > &X, int verbose_level)
void affine_cipher(std::string &ptext, std::string &ctext, int a, int b)
int solovay_strassen_test_iterated_with_latex_key(std::ostream &ost, ring_theory::longinteger_object &P, int nb_times, int verbose_level)
void vigenere_analysis(std::string &ctext)
int solovay_strassen_is_prime(ring_theory::longinteger_object &n, int nb_tests, int verbose_level)
void calc_roots(ring_theory::longinteger_object &M, ring_theory::longinteger_object &sqrtM, std::vector< int > &primes, std::vector< int > &R1, std::vector< int > &R2, int verbose_level)
void do_miller_rabin(int p, int nb_times, int verbose_level)
void polynomial_center_lift(std::string &A_coeffs, field_theory::finite_field *F, int verbose_level)
void print_candidates(std::string &ctext, int i, int h, int nb_candidates, int *candidates)
int solovay_strassen_test(ring_theory::longinteger_object &n, ring_theory::longinteger_object &a, int verbose_level)
void do_number_of_primitive_roots_interval(long int p_min, long int p_max, int verbose_level)
void do_inverse_mod(long int a, long int n, int verbose_level)
void do_primitive_root(long int p, int verbose_level)
void calc_log2(std::vector< int > &primes, std::vector< int > &primes_log2, int verbose_level)
void do_extended_gcd(int a, int b, int verbose_level)
void do_RSA_encrypt_text(long int RSA_d, long int RSA_m, int RSA_block_size, std::string &RSA_encrypt_text, int verbose_level)
int fermat_test_with_latex_key(std::ostream &ost, ring_theory::longinteger_object &n, ring_theory::longinteger_object &a, int verbose_level)
void square_root(std::string &square_root_number, int verbose_level)
void affine_decipher(std::string &ctext, std::string &ptext, std::string &guess)
void do_solovay_strassen(int p, int a, int verbose_level)
int miller_rabin_test_iterated_with_latex_key(std::ostream &ost, ring_theory::longinteger_object &P, int nb_times, int verbose_level)
void polynomial_reduce_mod_p(std::string &A_coeffs, field_theory::finite_field *F, int verbose_level)
void do_EC_baby_step_giant_step_decode(field_theory::finite_field *F, int EC_b, int EC_c, std::string &EC_bsgs_A, int EC_bsgs_N, std::string &EC_bsgs_cipher_text_T, std::string &EC_bsgs_keys, int verbose_level)
int EC_evaluate_RHS(field_theory::finite_field *F, int EC_b, int EC_c, int x)
void print_set(int l, int *s)
double friedman_index(int *mult, int n)
void do_EC_points(field_theory::finite_field *F, std::string &label, int EC_b, int EC_c, int verbose_level)
void square_root_mod(std::string &square_root_number, std::string &mod_number, int verbose_level)
int fermat_test_iterated_with_latex_key(std::ostream &ost, ring_theory::longinteger_object &P, int nb_times, int verbose_level)
void double_frequencies(std::string &text, int *mult)
void analyze(std::string &text)
void vigenere_analysis2(std::string &ctext, int key_length)
void vigenere_decipher(std::string &ctext, std::string &ptext, std::string &key)
int miller_rabin_test_with_latex_key(std::ostream &ost, ring_theory::longinteger_object &n, int iteration, int verbose_level)
void do_smallest_primitive_root(long int p, int verbose_level)
void make_2D_plot(int *orbit, int orbit_len, int cnt, int m, int a, int c, int verbose_level)
void do_primitive_root_longinteger(ring_theory::longinteger_object &p, int verbose_level)
void do_smallest_primitive_root_interval(long int p_min, long int p_max, int verbose_level)
int factor_over_factor_base(ring_theory::longinteger_object &x, std::vector< int > &primes, std::vector< int > &factor_idx, std::vector< int > &factor_exp, int verbose_level)
void quadratic_sieve(int n, int factorbase, int x0, int verbose_level)
void do_EC_add(field_theory::finite_field *F, int EC_b, int EC_c, std::string &pt1_text, std::string &pt2_text, int verbose_level)
int solovay_strassen_test_with_latex_key(std::ostream &ost, ring_theory::longinteger_object &n, ring_theory::longinteger_object &a, int verbose_level)
void get_k_bit_random_pseudoprime(ring_theory::longinteger_object &n, int k, int nb_tests_solovay_strassen, int f_miller_rabin_test, int verbose_level)
void single_frequencies(std::string &text, int *mult)
void do_EC_multiple_of(field_theory::finite_field *F, int EC_b, int EC_c, std::string &pt_text, int n, int verbose_level)
void do_find_pseudoprime(int nb_digits, int nb_fermat, int nb_miller_rabin, int nb_solovay_strassen, int verbose_level)
a collection of functions related to sorted vectors
int int_vec_search(int *v, int len, int a, int &idx)
void int_vec_heapsort(int *v, int len)
int frobenius_power(int a, int frob_power)
basic number theoretic functions
void sieve(std::vector< int > &primes, int factorbase, int verbose_level)
long int mod(long int a, long int p)
long int mult_mod(long int a, long int b, long int p)
void elliptic_curve_addition(field_theory::finite_field *F, int b, int c, int x1, int x2, int x3, int y1, int y2, int y3, int &z1, int &z2, int &z3, int verbose_level)
void elliptic_curve_all_point_multiples(field_theory::finite_field *F, int b, int c, int &order, int x1, int y1, int z1, std::vector< std::vector< int > > &Pts, int verbose_level)
long int primitive_root_randomized(long int p, int verbose_level)
long int gcd_lint(long int m, long int n)
long int power_mod(long int a, long int n, long int p)
void print_factorization(int nb_primes, int *primes, int *exponents)
long int add_mod(long int a, long int b, long int p)
int elliptic_curve_discrete_log(field_theory::finite_field *F, int b, int c, int x1, int y1, int z1, int x3, int y3, int z3, int verbose_level)
void elliptic_curve_point_multiple(field_theory::finite_field *F, int b, int c, int n, int x1, int y1, int z1, int &x3, int &y3, int &z3, int verbose_level)
long int primitive_root(long int p, int verbose_level)
long int euler_function(long int n)
int Jacobi_with_key_in_latex(std::ostream &ost, long int a, long int m, int verbose_level)
int get_prime_from_table(int idx)
long int inverse_mod(long int a, long int p)
int factor_int(int a, int *&primes, int *&exponents)
a collection of functions related to file io
void int_matrix_write_csv(std::string &fname, int *M, int m, int n)
void int_vec_write_csv(int *v, int len, std::string &fname, const char *label)
void lint_matrix_write_csv(std::string &fname, long int *M, int m, int n)
long int file_size(std::string &fname)
interface to create latex output files
void head(std::ostream &ost, int f_book, int f_title, const char *title, const char *author, int f_toc, int f_landscape, int f_12pt, int f_enlarged_page, int f_pagenumbers, const char *extras_for_preamble)
void foot(std::ostream &ost)
interface to system functions
int random_integer(int p)
void time_check_delta(std::ostream &ost, int dt)
domain to compute with objects of type longinteger
void extended_gcd(longinteger_object &a, longinteger_object &b, longinteger_object &g, longinteger_object &u, longinteger_object &v, int verbose_level)
int jacobi(longinteger_object &a, longinteger_object &m, int verbose_level)
int compare(longinteger_object &a, longinteger_object &b)
void integral_division_exact(longinteger_object &a, longinteger_object &b, longinteger_object &a_over_b)
int square_root_mod(int a, int p, int verbose_level)
int multiplicity_of_p(longinteger_object &a, longinteger_object &residue, int p)
void power_longint_mod(longinteger_object &a, longinteger_object &n, longinteger_object &m, int verbose_level)
void add(longinteger_object &a, longinteger_object &b, longinteger_object &c)
void integral_division_by_int(longinteger_object &a, int b, longinteger_object &q, int &r)
void mult(longinteger_object &a, longinteger_object &b, longinteger_object &c)
void random_number_with_n_decimals(longinteger_object &R, int n, int verbose_level)
void square_root(longinteger_object &a, longinteger_object &sqrt_a, int verbose_level)
void mult_mod(longinteger_object &a, longinteger_object &b, longinteger_object &c, longinteger_object &m, int verbose_level)
void random_number_less_than_n(longinteger_object &n, longinteger_object &r)
void create_Mersenne(longinteger_object &M, int n)
void power_int(longinteger_object &a, int n)
int remainder_mod_int(longinteger_object &a, int p)
void power_int_mod(longinteger_object &a, int n, longinteger_object &m)
int compare_unsigned(longinteger_object &a, longinteger_object &b)
a class to represent arbitrary precision integers
void create_from_base_10_string(const char *str, int verbose_level)
void assign_to(longinteger_object &b)
void create(long int i, const char *file, int line)
domain of polynomials in one variable over a finite field
void add(unipoly_object a, unipoly_object b, unipoly_object &c)
void center_lift_coordinates(unipoly_object a, int q)
void mult_mod(unipoly_object a, unipoly_object b, unipoly_object &c, unipoly_object m, int verbose_level)
int & s_i(unipoly_object p, int i)
void create_object_of_degree(unipoly_object &p, int d)
int degree(unipoly_object p)
void print_object(unipoly_object p, std::ostream &ost)
#define Int_vec_scan(A, B, C)
#define Int_vec_zero(A, B)
#define Lint_vec_scan(A, B, C)
#define Lint_vec_print(A, B, C)
#define Int_vec_print(A, B, C)
int sqrt_mod_involved(int a, int p, int verbose_level)
the orbiter library for the classification of combinatorial objects