Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 59
Image: ubuntu2004
1
def isqrt(n):
2
return int(floor(sqrt(n)))
3
4
def usqrt (n):
5
ur = isqrt(n)
6
if ur ** 2 < n:
7
ur = ur + 1
8
return(ur)
9
10
def FermatAttack (n, rounds):
11
st = usqrt(n)
12
for x in range(st, st + rounds + 1):
13
sq = x ** 2 - n
14
y = isqrt(sq)
15
if y ** 2 == sq:
16
print("Factor found in round {0}".format( x - st + 1))
17
return(x + y)
18
print("No factors found in {0}".format( rounds))
19