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

add invers_modulaire

parent d60af533
Branches
No related tags found
No related merge requests found
...@@ -34,6 +34,19 @@ def bachet_bezout(a, b): ...@@ -34,6 +34,19 @@ def bachet_bezout(a, b):
return a, u[i-2], v[i-2] 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): def exponentiation_rapide(a, exp, n):
"""Does the quick explanation of a pow x modulo n """Does the quick explanation of a pow x modulo n
...@@ -108,4 +121,3 @@ def fermat_factorization(n): ...@@ -108,4 +121,3 @@ def fermat_factorization(n):
a += 1 a += 1
return (a, b) return (a, b)
import algo from algo import *
def main(): def main():
mu = { mu = {
31726849986005826981, 416687707,
305966565717393601613, 420774592,
61497322861823383198, 1078076801,
269645690420162032117, 372477309,
155457162093765938384, 1915438026,
24931468152962121635, 306996859,
138444967690527010216, 1858268340,
282789589899417404817, 1934595642,
134251529920691060404, 444729462,
423054566352157178418, 1953792398,
265453042944217161627, 1118037789,
39119050384849643825 1220832721,
701508709,
1976470330,
1081245832,
1480954262,
921801986,
1154526486,
1974597168,
812527863,
1895548977,
1274512749,
712992858
} #encrypted message } #encrypted message
n = 1989929159 #first element public key
n = 4556490129 * pow(10, 11) + 89940178621 #first element public key e = 2203 #second element public key
e = 5303 #second element public key
length = length(mu) length = length(mu)
...@@ -38,7 +48,7 @@ def main(): ...@@ -38,7 +48,7 @@ def main():
fi = (p - 1) * (q - 1) fi = (p - 1) * (q - 1)
d = inverse_modulaire(e, fi) d = inverse_modulaire(e, fi)
#// --- decode mu & initialise msg --- # --- decode mu & initialise msg ---
for i in range(length): for i in range(length):
M[i] = exponentiation_rapide(mu[i], d, n) 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