Illustration of RSA Algorithm: p,q=5,7

This section provides a tutorial example to illustrate how RSA public key encryption algorithm works with 2 small prime numbers 5 and 7.

To demonstrate the RSA public key encryption algorithm, let's start it with 2 smaller prime numbers 5 and 7.

Generation the public key and private key with prime numbers of 5 and 7 can be illustrated as:

```Given p as 5
Given q as 7
Compute n = p*q: n = 5*7 = 35
Compute m = (p-1)*(q-1): m = 4*6 = 24
Select e, such that e and m are coprime numbers: e = 5
Compute d, such that d*e mod m = 1: d = 29
The public key {n,e} is = {35,5}
The private key {n,d} is = {35,29}
```

With the public key of {35,5}, encryption of a cleartext M represented as number 23 can be illustrated as:

```Given public key {n,e} as {35,5}
Given cleartext M represented in number as 23
Divide B into blocks: 1 block is enough
Compute encrypted block C = M**e mod n:
C = 23**5 mod 35 = 6436343 mod 35 = 18
The ciphertext C represented in number is 18
```

With the private key of {35,29}, decryption of the ciphertext C represented as number 18 can be illustrated as:

```Given private key {n,e} as {35,29}
Given ciphertext C represented in number as 18
Divide C into blocks: 1 block is enough
Compute encrypted block M = C**d mod n:
M = 18**29 mod 35
= 18*18**28 mod 35
= 18*(18**4)**7 mod 35
= 18*(104976)**7 mode 35
= 18*(104976 mod 35)**7 mod 35
= 18*(11)**7 mod 35
= 18*19487171 mod 35
= 350769078 mod 35
= 23
The cleartext M represented in number is 23
```

Cool. RSA public key encryption algorithm works. We are getting the original cleartext 23 back using the decryption algorithm and private key!

Notice that I had to compute "18**29 mod 35" in multiple steps, because 18**29 is too big to be computed directly.