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.
Where you have
you seem to want to check "Is
d*e
equal (modz
) to1
"But what you're doing is performing
1 % z
(which gives1
) and checking ifd * e
is equal to1
.Change it to:
and it should do the calculation you intend.