(adsbygoogle = window.adsbygoogle || []).push({});
Given n as the modulus, and exponents d & e, this python function returns the factors of n as an array:
Code:
def rfact(n, e, d):
""" because e*d is congruent to 1 mod phi(n), e*d is very close to
being a multiple of phi, and phi is very close to n for an RSA
modulus - so the whole number quotient (e*d)/n is 1 less than
this factor """
k = 1 + (e * d) / n
phi = (e * d - 1) / k
""" if n=p*q, then phi(n) = (p-1)*(q-1) = p*q + 1 - (p+q); but p*q=n,
so phi(n) = n + 1 - (p+q); set 'sum' to p+q """
sum = n + 1 - phi
""" we now know the product of p and q (n) and their sum (sum). we
solve for p and q using the quadratic formula. set 'delta' to
the radical in the numerator of the formula """
delta = isqrt(sum**2 - 4*n)
p = (sum + delta) / 2
q = (sum - delta) / 2
if p*q != n:
print '!Failed: modulus not factored correctly!'
return [p, q]
Function rfact() requires this integer square root function:
Code:
def isqrt(n):
# construct an initial guess value
d = len(str(n)) # count of decimal digits
x = '3'
d = d / 2
while d > 0:
d = d - 1
x = x + '1'
x = int(x)
# perform Newton-Raphson iteration
prev = 0
while x != prev:
prev = x
q = n / x
x = (x + q) / 2
return x
could anyone run this script using ps3 paramters my cpu cant hang
DISCLAIMERS: 1) This code is offered without any warranty. If your computer catches fire when you try to run it, don't say I didn't warn you. 2) If you don't know how to run python code, search the interwebs: tons of python info!