K * G == 1At first it would seem that this could only be true if K and G were both equal to 1. But, that's the reason we are using mod R arithmetic. What we are really saying is that after dividing K*G by R, the remainder must be one, or:
(K * G) % R == 1Using our example values:
(31 * G) % 616 == 1Finding G is a bit tricky, but using a computer program and just trying different values works for these small examples. The correct answer for G is 159. To confirm this, 31*159 yields 4929. If we divide 4929 by 616 we get a quotient of 8 and a remainder of 1. So G = 159 is our private decryption key.
C = (M^K)%N = (65^31)%667That is, all calculations are made mod N. Now it turns out that in calculating M to the Kth power, we get the correct answer even if at each step along the way, we apply the mod N operation. This keeps our number from getting too large. (FN: What we are using is the identity (x % y) * (x % y) == (x * x) % y.)
M = (C^G)%N = (103^159)%667 = 65.Again, all of the calculations are done mod N and this results in our seeing her original message, 65. Success!