I have a very basic doubt in RSA key generation and its usage.
In RSA key generation you choose two large prime numbers of a very large order. Then you multiply them.(eq p * q = N)
Now, Euler(N)=(p-1)(q-1). Now you find a number 0 < e < Euler(N) such that e and Euler(N) are coprime. {e.Euler(N)} becomes your public key. Now you compute d(private key) such that e * d =1 (mod(Euler(N))).
Now suppose you encrypt something(m) with your the public key – c=m^e(mod(N)).
And now while decrypting with the private key(d), you do c^d(mod(N)).
Now my doubt is that you found out the inverse of e in mod(Euler(N)), but when you are decrypting you are doing it in mod(N). How is this possible?
See wikipedia here and here. Basically, you want decryption to “undo” encryption. Since e⋅d = 1 mod φ(N) is equivalent to e⋅d = 1 + k⋅φ(N) for some integer k, you have:
cd mod N = (me)d mod N = m(e⋅d) mod N = m(1 + k⋅φ(N)) = (m1) ⋅ (mφ(N))k mod N
by application of the following rules you learned in algebra:
1) axy = (ax)y = (ay)x, and
2) ax+y = ax ⋅ ay
To finish this and simplify (m1) ⋅ (mφ(N))k mod N, remember that aφ(N) = 1 mod N, so
(mφ(N))k mod N = 1k = 1 mod N.