Salut, j'essaye de chiffrer et déchiffrer des message, mais je rencontre un gros soucis.
Le problème vient de cette fonction :
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 BigInt BigInt::m_invert(const BigInt& b) const { BigInt n0 = b; BigInt b0 = *this; BigInt t0 (0, true, base); BigInt t (1, true, base); BigInt q = n0/b0; BigInt r = n0 - (q * b0); BigInt temp = 0; while (r > 0) { temp = t0 - (q * t); if (temp >= 0) temp = temp % b; else temp = b - ((temp) % b); t0 = t; t = temp; n0 = b0; b0 = r; q = n0/b0; r = n0 - (q * b0); } if (b0 != 1) return 0; else return t; }
J'ai testé tout mes fonctions *, /, %, modOfPow, etc..., et elles fonctionnent bien, cependant, je n'obtiens pas le même caractère après déchiffrement :
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 BigInt p (503, true, 16); BigInt q (563, true, 16); n = p * q; BigInt f = (p - 1) * (q - 1); while (d == 0) { do { e = BigInt::genRandom(32, 16); } while (BigInt::pgcd(e,f) != 1 && BigInt::pgcd(e, n) != 1); d = e.m_invert(f); } BigInt ascii (5, true, 16); BigInt c = ascii.modOfPow(e, n); std::cout<<c.modOfPow(d, n)<<std::endl;
J'en déduis donc que c'est la fonction m_invert qui me renvoie des mauvaises valeur pour d.
Mais je ne comprend pas pourquoi, j'ai pourtant bien recopier l'algorithme.
Merci d'avance pour votre aide.
Partager