Presque-presque
This commit is contained in:
parent
155d7bbe64
commit
64f4f44752
15
etape5.c
15
etape5.c
@ -1,6 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* n = p * q => p et q sont des nombres premiers
|
/* n = p * q => p et q sont des nombres premiers
|
||||||
e = pgcd(e,(p-1)(q-1))
|
e = pgcd(e,(p-1)(q-1))
|
||||||
@ -58,6 +57,15 @@ premier findPq(unsigned long long int n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long long int multiplicationCommeDHabitude(unsigned long long int e, unsigned long long int i, unsigned long long int phi)
|
||||||
|
{
|
||||||
|
if (i < 1000 && e < 1000)
|
||||||
|
{
|
||||||
|
return i * e % phi;
|
||||||
|
}
|
||||||
|
return multiplicationRapide(e / 2, i / 2, phi) + multiplicationRapide(e / 2 ,i / 2, phi);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
/*Parametres RSA*/
|
/*Parametres RSA*/
|
||||||
unsigned long long int n = 1028648100739351553;
|
unsigned long long int n = 1028648100739351553;
|
||||||
@ -67,10 +75,13 @@ int main(void) {
|
|||||||
/* Recherche des nombres premiers p et q */
|
/* Recherche des nombres premiers p et q */
|
||||||
premier facteurs = findPq(n);
|
premier facteurs = findPq(n);
|
||||||
phi = (facteurs.p - 1)*(facteurs.q - 1);
|
phi = (facteurs.p - 1)*(facteurs.q - 1);
|
||||||
|
printf("phi = %llu\n", phi);
|
||||||
|
|
||||||
/* Calcul de la cle privee d a partir de la formule : (e*d) mod phi = 1 */
|
/* Calcul de la cle privee d a partir de la formule : (e*d) mod phi = 1 */
|
||||||
for (unsigned long long int i = 1; i < phi; i++) {
|
for (unsigned long long int i = 1; i < phi; i++) {
|
||||||
if (e * i % phi == 1) {
|
unsigned long long int resultat = multiplicationRapide(e, i, phi);
|
||||||
|
printf("resultat = %llu\n", resultat);
|
||||||
|
if (resultat == 1) {
|
||||||
d = i;
|
d = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user