# Is there a cleaner way to find p*q = n, when p and q are co-prime?

Basically trying to write a simple RSA brute force. I have modulus N and I'm trying to find p*q=n where p and q are co-primes.

So far i'm able to find the prime factors of N and I can put them in a list. Then taking that list apart into variables then going through each pair to find co-primes. It's messy, and was wondering if there was a cleaner way of doing it?

my code so far:

``````from fractions import gcd
import sys

n= 17
print "Modulus (n) = ", n
print("p & q are:")

# While Loop to find prime factors
i=1
list=[]
while(i<=n):
k=0
if(n%i==0):
j=1
while(j<=i):
if(i%j==0):
k=k+1
j=j+1
if(k==2):
list.append(i)
i=i+1

# takes list of prime factors and splits to variables
for n, val in enumerate(list):
globals()["var%d"%n] = val

# really messy, tries to multiply first 2 variables, if co-prime, print the variables
# if no co-prime factors move on to next 2 variables
# if no prime factors in the first place, exit
try:
gg0 = gcd(var0,var1)
except:
print "No Prime Factors"
sys.exit()

try:
gg1 = gcd(var1,var2)
if gg1 == True:
print var1, var2
except:
if gg0 == True:
print var0, var1
``````