Public key encryption system has three parts:
A private key and a public key will be generated from two prime numbers.
First, we need the public key of the person to whom we want to send the message.
Next we need the message. For simplicity, use just one letter.
In secure applications letters are never encrypted individually, but in whole blocks.
The value of m' is the encrypted message and is sent to the recipient.
First we need the private key of the recipient of the encrypted message.
Two numbers are said to be relatively prime when they have no divisor in common. In other words, their greatest common divisor (GCD) is 1.
The greatest common divisor can be efficiently computed via the Euclidean Algorithm.
The greatest common divisor d of two numbers, m and n can be written as
The computation of the cofactors is useful for finding the multiplicative inverse of a number n with respect to a module m.
Given two relatively prime numbers, m and n, such that the value of their GCD is 1 the cofactors are
And therefore c2 x n % m = 1
Thus c2 is the multiplicative inverse of n % m
Both encryption and decryption need a power reduced modulo of module m. It is inefficient to compute the whole power before starting the modulo computation as it involves large numbers. Thus, a more efficient method is reducing the intermediate powers of modulo m.
Congratulations! You have successfully investigated and witnessed how RSA public key cryptosystem works.