def gcd(e, z):
if z == 0:
return e
else:
return gcd(z, e % z)
e = int(input("Please enter the first number:"))
z = int(input("Please enter the second number:"))
print ("The GCD of ",e," and ",z," is ",gcd(e,z))
d = 1
while d < e:
if d * e == 1 % z:
print (d," * ",e," = 1 (mod ",z,")")
d = d + 1
else:
d = d + 1
I am trying to use this code to find candidates for rsa by brute force it seems like it should work but it doesn't can anyone help me out?
z = (p − 1)(q − 1) for the calculation of z is used prior to this with p = 47 and q = 59, e = 17 and d = 157 but after the program runs it finds no matches but it should.
1 % z
is always1
... what did you expect this to mean? – Steiger(d*e)%z==1
– Steiger1 (mod z)
is always 1 (forz > 1
). Butde (mod z)
is not alwaysde
. So you're doing the modulus remainder on the wrong side. (Of course technically speaking, you should do it on both sides, but the point is, you can skip the right, and you can't skip the left.) – Nobile