For a contest I am trying to learn how to break a RSA key given only the public key:
- e = 65537
- n = 632459103267572196107100983820469021721602147490918660274601
So I followed this webpage and this answer. And tried:
>>> n = 632459103267572196107100983820469021721602147490918660274601
>>> import math
>>> math.floor(math.sqrt(n))
795272974058324394239265341440
>>> c = math.floor(math.sqrt(n))
>>> for i in range(c-1,c-41,-2):
... if c%i ==0:
... print(i, c%i)
...
But it doesn't give me anything. I have started a brute force approach:
>>> print(repr(math.sqrt(n)))
7.952729740583244e+29
>>> c = math.sqrt(n)
>>> int(c)
795272974058324394239265341440
>>> for i in range(c-1, 2, -2):
... if n%i == 0:
... print(i, n%i)
...
But it has been running for half a day. I know it is stupid because I am testing even not prime numbers. Is there a wiser way?
At the very beginning I started with c, which is an even number. I guess that decreasing with a step 2 from an even number is stupid as it only leads me to test non factorizer?
Update
After reading Dan's comment, I am now trying to search for a small factor rather than start from the big one.
>>> for i in range(1,c-1,2):
... if c%i ==0 and i%2 != 0 and i%5 !=0:
... print(i, c%i)
...
1 0