RSA (named after Rivest – Shamir โ€“ Adleman) is a popularly used public key encryption system. Security of RSA is based on the fact that it is very difficult to factorize a very long integer into its prime factors.

Being public key crypto system, it involves the usage of public key and private key for encryption and decryption. Here the public key pair is made public to everyone and the private key is maintained in secrecy.

There are 3 simple steps to implement RSA

  • Key Generation
  • Encryption
  • Decryption

Key generation

Lets consider 2 large primes p and q

Set modulus n = pq

As both p and q are prime their totient ๐œ‘(n) = (p-1)(q-1)

Select the public exponent e such that gcd(e,๐œ‘(n)) = 1 and 1<e<๐œ‘(n)

Now we got to determine our private key d such that ed = 1 mod ๐œ‘(n) i.e d = e-1 mod ๐œ‘(n)

d is known as modular multiplicative inverse of e as e and ๐œ‘(n) are relatively prime and hence d can be calculated using Euclidean Extended Theorem. (e,n) are known as public key pair where as (d,n) are known as the private key pair


Now we have our required keys generated and also the modulus required for encryption. We take a random message m such that m is less than the modulus n. We encrypt our message m as

c = me mod n


Once we have the encrypted message c we can get the decrypted message using the generated private key

pt = cd mod n

So,how can we say that both decrypted message and original message are the same? The only answer to this question is to prove it


pt = cd mod n

pt = med mod n but ed = 1 + k(๐œ‘(n))

pt = m1+k(๐œ‘(n)) mod n by Eulerโ€™s theorem we know that m๐œ‘(n) =1 mod n

pt = m(mk(๐œ‘(n))) mod n

pt = m mod n

As we know that m < n we can say m = m mod n

so we proved that pt =m

So thatโ€™s all for this post. Please do correct me if you find any mistakes


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s