Public Key Encryption – RSA

RSA is a public-key cryptosystem developed by Ron Rivest, Adi Shamir and Leonard Adleman and published in 1977. The encryption key (public key) and the decryption key (secret key) are distinct. Anyone can encrypt the message but only whom keeps the secret key can decrypt it.

From an original message m, the encrypted message is created by powering it to an “encryption factor” and modulo to an appropriate value k, calculated by: mencryption factormodk=M

And then, from the encrypted message M, the original message m can be recorvered by powering it to a “decryption factor” and also modulo to kMdecryption factormodk=m

This means mencryption factor * decryption factormodk=m, this implies:

mencryption factor * decryption factor11(modk)

Let the “encryption factor” be revealed to the public for encryption and the “decryption factor” be used to decrypt a message and kept private. But how to find those keys, and especially, how to find k?

Moving next, the Euler’s Theorem and the totient function ϕ(n)

For any a,nN,gcd(a,n)=1, then aϕ(n)1(modn) in which ϕ(n) is the totient function defined by:

ϕ(n)=|{0<x<n,gcd(n,x)=1}|

Some properties of the totient function:

  1. ϕ(1)=1

  2. If gcd(a,b)=1, then ϕ(a)ϕ(b)=ϕ(ab)

  3. If p is a prime, then ϕ(p)=p1

Applying the Euler’s theorem to the encryption scheme

If letting the original message m to be a, then the target is to find an appropriate n satisfying:

  1. gcd(a,n)=1

  2. t.ϕ(n)+1=encryption factor×decryption factor,t>0,tN

The RSA Algorithm

  1. Choose 2 prime numbers: p,q

  2. Calculate n=p.q,ϕ(p)=p1,ϕ(q)=q1ϕ(n)=(p1)(q1)

  3. Choose d,eN such that: d.e=1+t.ϕ(n),t>0,tN. This is written in the algorithm as:

    1. Choose \(1

    2. Choose d such that d.e1(modϕ(n))

  4. The public key is pk=(n,e) and secret key is sk=(d,n)

Encryption: M=memodn

Decryption: m=Mdmodn

It is clearly seen that: Mdmodn=(meM)dmodn=me.dmodnmodn=m

Hope this post helps you a better understanding.
You could find an interactive demo of this algorithm here.

Subscribe to SkyGLab

Scroll to Top