Presque-presque

This commit is contained in:
SombrAbsol 2024-01-24 19:54:22 +01:00
parent 155d7bbe64
commit 64f4f44752
2 changed files with 13 additions and 2 deletions

BIN
a.exe Normal file

Binary file not shown.

View File

@ -1,6 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
/* n = p * q => p et q sont des nombres premiers
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) {
/*Parametres RSA*/
unsigned long long int n = 1028648100739351553;
@ -67,10 +75,13 @@ int main(void) {
/* Recherche des nombres premiers p et q */
premier facteurs = findPq(n);
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 */
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;
break;
}