I have two numbers, p, and q. I know that I can get phi = (p-1)*(q-1) and that ed = 1 (mod phi)… but I’m not sure I get what this means.
I wrote some Python:
p = NUM
q = NUM
e = NUM
phi = (p-1)*(q-1)
d = (1 % phi)/float(e)
But I always get a decimal, and d is supposed to be an integer. what am I doing wrong?
EDIT: I may just not understand RSA. Right now, I’m looking at this page: http://www.di-mgt.com.au/rsa_alg.html
Your understanding of the math is wrong. The equation
means that, the remainder of number ed dividing φ is equal to 1, i.e. in terms of Python,
For instance, if φ = (7 – 1)(11 – 1) = 60, and e = 17, then if we choose d = 53, then we’ll get
We call d a modular multiplicative inverse of e.
To generate d from e and φ, usually extended Euclidean algorithm is used. Please read http://en.wikipedia.org/wiki/Modular_multiplicative_inverse or https://stackoverflow.com/search?q=python+%22multiplicative+inverse%22&submit=search for more info