cryptanalysis_scripts/fermat_factorisation.py

17 lines
297 B
Python
Raw Normal View History

import math
import decimal
def factorise(n):
x = math.ceil(math.sqrt(n))
y = x ** 2 - n
while not math.sqrt(y).is_integer():
x += 1
y = x ** 2 - n
return x + math.sqrt(y), x - math.sqrt(y)
n = 1364593
print("Die beiden Faktoren p und q lauten:", factorise(n))