I'm writing a program that will calulate the private key for a weak RSA public key. I am wondering how I would go about determining the values for `p` and `q` from the value `n`. Here is the Python code so far:

```py
from Crypto.PublicKey import RSA #PyCryptoDome
import .math as cm # My own module

with open(public_keyfile, 'rb') as key: # Public Keyfile Is in PEM format
    public_key = RSA.import_key(key)

n = public_key.n # N value of the public_key

e = public_key.e # E value of the public_key

p, q = get_factors_of(n) # This I don't know how to do, though there is a question that might help [see bottom]

t = cm.lcm(p-1, q-1) # Get the lowest common multiple of q and q

d = cm.mod_inverse(e, t) # Get d, the modular inverse of e % t

private_key = RSA.construct((n, e, d, p, q) # Construct the RSA private_key

```

The `.math` module referenced above:

```py
from math import gcd

def mod_inverse(a, b):
    a = a % b
    for x in range(1, b):
        if (a * x) % b == 1:
            return x
    return 1

def lcm(x, y):
    return x * y // gcd(x, y)

```

What I need to do appears to be referenced 
[here](https://stackoverflow.com/questions/45164709/finding-a-p-and-q-of-n-pq-from-when-p-and-q-are-prime-numbers) but this code is in Java.

If anyone knows how to get `p` and `q` from `n` with python, help would be appreciated. 

Many thanks, Legorooj.