Purpose of the page is to demonstrate how RSA algorithm works - generates keys, encrypts message and decrypts it.

See the related blog post for more explanation.

Public Key Cryptography using RSA algorithm

Purpose of the page is to demonstrate how RSA algorithm works - generates keys, encrypts message and decrypts it.

See the related blog post for more explanation.

Enter two prime numbers below (P, Q), then press calculate:

P:

Q:

Some prime numbers: 11, 13, 17, 19, 23, 29, 191, 193, 197, 199, etc.

Variable | Value | Name | Formula | Description |
---|---|---|---|---|

N | modulus | N: P * Q | Product of 2 prime numbers | |

L | length | L: (p - 1) * (q - 1) | Another way of calculating 'L' is to list of numbers from 1 to N, remove numbers which have common factor which N and count the remaining numbers. | |

E | encryption key | Find a number between 1 and L that is coprime with L and N. | ||

D | decryption key | D * E mod L = 1 | Remainder of the product of D and E when divided by L should be 1 (D * E % L = 1) |

Private Key (E, N):

Public Key (D, N):

Enter a message to encrypt:

Message converted to ASCII code:

Encrypted message: message^E % N (PowerMod can be used to calculate this very fast. Formula is applied on ASCII code of each character.)

Encrypted Message:

Enter a encrypted message (cipher):

Message decrypted to ASCII code:

Decrypted Message: encrypted_message^D % N (PowerMod can be used to calculate this very fast. Formula is applied on ASCII code of each character.)

Decrypted Message: