├── README.md └── fermats_factorizer.py /README.md: -------------------------------------------------------------------------------- 1 | # rsa_tool 2 | 3 | A python script written with the intend to demonstrate a vulnerability in [rsa cryptography](https://en.wikipedia.org/wiki/RSA_(cryptosystem)). 4 | 5 | The vulnerability exists only if the two large primes that are chosen to compute n are very close to each other (the distance between the numbers can be iterated in feasible time limits). 6 | 7 | In such a scenario on can use [fermat factorization](https://en.wikipedia.org/wiki/Fermat%27s_factorization_method). 8 | -------------------------------------------------------------------------------- /fermats_factorizer.py: -------------------------------------------------------------------------------- 1 | import math 2 | import gmpy2 3 | 4 | N=gmpy2.mpz(E8953849F11E932E9127AF35E1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000051F8EB7D0556E09FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBAD55) 5 | 6 | gmpy2.get_context().precision=2048 7 | a=int(gmpy2.sqrt(n)) 8 | 9 | a2=a*a 10 | b2=gmpy2.sub(a2,N) 11 | 12 | while not(gmpy2.is_square(b2)): 13 | a=a+1 14 | b2=a*a-N 15 | 16 | b2=gmpy2.mpz(b2) 17 | gmpy2.get_context().precision=2048 18 | b=int(gmpy2.sqrt(b2)) 19 | 20 | print a+b 21 | 22 | print a-b 23 | --------------------------------------------------------------------------------