Commit 2ba5f6ec authored by Elena Biasi's avatar Elena Biasi
Browse files

ajout fonctions

parent 44ce0d1a
......@@ -123,14 +123,25 @@ def EuclideEtendu(a,b):
return u1, v1
def inverseMod(x,b):
return (x % b + b) % b
return (x % b + b) % b
def lpowmod(x, y, n):
"""puissance modulaire: (x**y)%n avec x, y et n entiers"""
result = 1
while y>0:
if y&1>0:
result = (result*x)%n
y >>= 1
x = (x*x)%n
return result
p,q = EuclideEtendu2(n, e, 1, 0, 0, 1)
nPrime = (p - 1)*(q - 1)
d = inverseMod(e, nPrime)
d = inverseMod(nPrime, e)
print(d)
d *= -1
for k in range(len(messages)):
tmp = inverseMod(int(pow(messages[k],d)),n)
tmp = inverseMod(n,lpowmod(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