Commit 44ce0d1a authored by Elena Biasi's avatar Elena Biasi
Browse files

ajout fonctions

parent 280d46e9
## Ricardo Dos Santos et Elena Biasi
## Ricardo Dos Santos, Elena Biasi et Martin Caron
## Math RSA
## HEPIA 2022
from itertools import combinations
from collections import Counter
import itertools
import math
n = 1329471887
e = 6587
messages = [
897236334,
70290717,
291590707,
785823228,
1014644654,
107011762,
37876730,
1006665847,
562389059,
46810230,
851017326,
888772621,
114923772,
950906679,
629976182,
616800432,
305188551,
257871665,
1316505187,
425775231,
339743649,
88610812,
1068356054,
1239206918,
246525967,
1014644654,
1131226650,
759759114,
923468242,
866697691,
658649513,
889610702,
961354073,
377426782,
1135610970,
692502072,
1277028126,
248262095,
115919706,
1316505187,
425775231,
339743649,
916364148,
185343990,
689830516,
384692413,
1136705425,
852776752,
1189257495,
462776220,
843706861,
1117814753,
955037039,
178276857,
1009905929
]
# fonction PGCD:
def pgcd(a,b):
if a < b:
tmp = a
a = b
b = tmp
while b != 0:
r = a % b
a = b
b = r
return a
# Fonction Euclide etendu (coeff bezout):
def EuclideEtendu2(a, b, x0, x1, y0, y1):
x = 0
y = 0
q = 0
r = 0
#quotient et reste
q = a / b
r = a % b
if (r == 0):
return x1, y1
else :
x = x0 - q * x1
y = y0 - q * y1
return EuclideEtendu2(b, r, x1, x, y1, y)
def EuclideEtendu(a,b):
if pgcd(a,b) == 1:
#a*u + b*v = pgcd(a,b)
r1 = b
r2 = a
u1 = 0
v1 = 1
u2 = 1
v2 = 0
while r2 != 0 :
q = r1 / r2
r3 = r1
u3 = u1
v3 = v1
r1 = r2
u1 = u2
v1 = v2
r2 = r3 - q*r2
u2 = u3 - q*u2
v2 = v3 - q*v2
return u1, v1
def inverseMod(x,b):
return (x % b + b) % b
p,q = EuclideEtendu2(n, e, 1, 0, 0, 1)
nPrime = (p - 1)*(q - 1)
d = inverseMod(e, nPrime)
d *= -1
for k in range(len(messages)):
tmp = inverseMod(int(pow(messages[k],d)),n)
print(tmp)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment