How to find d, given p, q, and e in RSA?

Given that, p=11, q=7, e =17, n=77, φ (n) = 60 and d=?

First substitute values from the formula:-

ed mod φ (n) =1

17 d mod 60 = 1

The next step: – take the totient of n, which is 60 to your left hand side and [e] to your right hand side.

60 = 17

3rd step: – ask how many times 17 goes to 60. That is 3.5….. Ignore the remainder and take 3.

60 = 3(17)

Step 4: – now you need to balance this equation 60 = 3(17) such that left hand side equals to right hand side. How?

60 = 3(17) + 9 <== if you multiply 3 by 17 you get 51 then plus 9, that is 60. Which means both sides are now equal.

Step 5: – Now take 17 to your left hand side and 9 to your right hand side.

17 = 9

Step 6:- ask how many times 9 goes to 17. That is 1.8…….

17 = 1(9)

Step 7:- Step 4: – now you need to balance this 17 = 1(9)

17 = 1(9) + 8 <== if you multiply 1 by 9 you get 9 then plus 8, that is 17. Which means both sides are now equal.

Step 8:- again take 9 to your left hand side and 8 to your right hand side.

9 = 1(8)

9 = 1(8) + 1 <== once you reached +1 to balance your equation, you may stop and start doing back substitution.

Step A:-Last equation in step 8 which is 9 = 1(8) + 1 can be written as follows: 1.= 9 – 1(8)

Step B:-We know what is (8) by simple saying 8 = 17 – 1(9) from step 7. Now we can re-write step A as:-

1=9 -1(17 – 1(9)) <== here since 9=1(9) we can re-write as:-

1=1(9)-1(17) +1(9) <== group similar terms. In this case you add 1(9) with 1(9) – that is 2(9).

1=2(9)-1(17)

Step C: – We know what is (9) by simple saying 9 = 60 – 3(17) from step 4. Now we can re-write step B as:-

1=2(60-3(17) -1(17)

1=2(60)-6(17) -1(17) <== group similar terms. In this case you add 6(17) with 1(17) – that is 7(17).

1=2(60)-7(17) <== at this stage we can stop, nothing more to substitute, therefore take the value next 17. That is 7. Subtract it with the totient.

60-7=d

Then therefore the value of d= 53.


Well, d is chosen such that d * e == 1 modulo (p-1)(q-1), so you could use the Euclidean algorithm for that (finding the modular multiplicative inverse).

If you are not interested in understanding the algorithm, you can just call BigInteger#modInverse directly.

 d = e.modInverse(p_1.multiply(q_1))

Tags:

Encryption

Rsa