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

force some float in int

parent f4988cf0
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,7 @@ def exponentiation_rapide(a, exp, n): ...@@ -56,7 +56,7 @@ def exponentiation_rapide(a, exp, n):
n (uint): the modulo n (uint): the modulo
Returns: Returns:
uint: An array with the pgdc and the coefficients of bachet_bezout, [pgdc, u, v] uint: The result of of the quick explanation
""" """
if (a == 0): if (a == 0):
...@@ -72,7 +72,7 @@ def exponentiation_rapide(a, exp, n): ...@@ -72,7 +72,7 @@ def exponentiation_rapide(a, exp, n):
b = (b**2) % n b = (b**2) % n
exp = exp // 2 exp = exp // 2
return r return int(r)
def is_square(a): def is_square(a):
"""Check if a number is a perfect square, using the Newton methode """Check if a number is a perfect square, using the Newton methode
...@@ -115,7 +115,7 @@ def fermat_factorization(n): ...@@ -115,7 +115,7 @@ def fermat_factorization(n):
b2 = a**2 - n b2 = a**2 - n
if (is_square(b2)): if (is_square(b2)):
b = math.sqrt(b2) b = int(math.sqrt(b2))
break break
a += 1 a += 1
......
from ast import For, arguments, parse
from cProfile import label
from operator import truediv
import sys
from algo import * from algo import *
def main(): def main():
mu = { mu = [
416687707, 416687707,
420774592, 420774592,
1078076801, 1078076801,
...@@ -29,16 +25,17 @@ def main(): ...@@ -29,16 +25,17 @@ def main():
1895548977, 1895548977,
1274512749, 1274512749,
712992858 712992858
} #encrypted message ] # encrypted message
n = 1989929159 # first element public key n = 1989929159 # first element public key
e = 2203 # second element public key e = 2203 # second element public key
length = length(mu) length = len(mu)
# --- private element --- # --- private element ---
M = [] # decriypted message M = [] # decriypted message
msg = "" # message (string) msg = "" # message (string)
p, q = 0 #primes numbers p = 0 # fisrt prime number
q = 0 # second prime number
d = 0 # private key d = 0 # private key
#--- crack RSA --- #--- crack RSA ---
...@@ -47,17 +44,17 @@ def main(): ...@@ -47,17 +44,17 @@ def main():
p = a + b p = a + b
q = a - b q = a - b
print(n == p * q, "\n")
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.append(exponentiation_rapide(mu[i], d, n))
for m in M: for m in M:
print(decode_msg(m), end='') msg += decode_msg(m)
print("p, q :", p, q, "\nfi :", fi, "\nd :", d, "\nmsg :", msg)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment