Skip to content
Snippets Groups Projects
Commit 4c33055c authored by adrian.spycher's avatar adrian.spycher
Browse files

add invers_modulaire

parent d60af533
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,19 @@ def bachet_bezout(a, b):
return a, u[i-2], v[i-2]
def inverse_modulaire(a, n):
"""Does the inverse modular of a by n, using Bachet-Bezout
Args:
a (uint): the number
n (uint): the modulo
Returns:
uint: the inverse modular
"""
return bachet_bezout(a, n)[1]
def exponentiation_rapide(a, exp, n):
"""Does the quick explanation of a pow x modulo n
......@@ -108,4 +121,3 @@ def fermat_factorization(n):
a += 1
return (a, b)
import algo
from algo import *
def main():
mu = {
31726849986005826981,
305966565717393601613,
61497322861823383198,
269645690420162032117,
155457162093765938384,
24931468152962121635,
138444967690527010216,
282789589899417404817,
134251529920691060404,
423054566352157178418,
265453042944217161627,
39119050384849643825
416687707,
420774592,
1078076801,
372477309,
1915438026,
306996859,
1858268340,
1934595642,
444729462,
1953792398,
1118037789,
1220832721,
701508709,
1976470330,
1081245832,
1480954262,
921801986,
1154526486,
1974597168,
812527863,
1895548977,
1274512749,
712992858
} #encrypted message
n = 4556490129 * pow(10, 11) + 89940178621 #first element public key
e = 5303 #second element public key
n = 1989929159 #first element public key
e = 2203 #second element public key
length = length(mu)
......@@ -38,7 +48,7 @@ def main():
fi = (p - 1) * (q - 1)
d = inverse_modulaire(e, fi)
#// --- decode mu & initialise msg ---
# --- decode mu & initialise msg ---
for i in range(length):
M[i] = exponentiation_rapide(mu[i], d, n)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment