Il cifrario RSA
RSA cipher: a demo with 2021 = 43 x 47
Cifrario RSA: il metodo - RSA è una permutazione

This page allows you to simulate the behavior of the RSA cipher (see the page RSA: the method for details); the user has to enter two distinct primes $p$ and $q$, and then the plain message, here a number less than $ N = pq $. As a default example we use the current year, $ 2021 = 43 \times 47 $ which happens to be the product of two prime numbers.

As usual we imagine two people Alice and Bob, who have to exchange a message in a secret way, in this case it is just a number, but obviously any text can be transformed into numbers using a code, typically the ASCII code.

In the table on the right below the various steps of the encryption process are visible, the last two rows show the encrypted message and the decrypted one which must obviously be equal to the initial number.

NB 1 To avoid overload please use only prime numbers less than $200$.

NB 2 Presently RSA is considered secure only for 1024, or better 2048 bits numbers (hundreds of decimal digits!!!). This page has only a demo purpose, so it can only handle small and readable numbers.

Data entry
$p$ (1st prime number)
$q$ (2nd prime number)
$m$ plain message (number)
($m < N$)
Alice chooses two prime numbers $p = 43$ e $q = 47$ and computes the product publishing the result.$N$
public key
$p \times q = 43 \times 47$ $2021$
Alice, knowing $p$ e $q$ easily computes Euler's function $\Phi(N)$ to be kept secret.$\Phi(N)$
private key

$\Phi(N) = (p - 1)(q - 1) = \Phi(2021) = 42 \times 46$
Alice computes the second key $e$, first number prime with $\Phi(N)$ and publishes it.$e$
public key
first number such that $MCD(e, \Phi(N)) = 1$$5$
Alice computes the secret key $d$, that is the inverse of $e$ modulo $\Phi(N)$ and does NOT publish it.$d$
private key
$d$ so that $ e \times d \equiv 1 \pmod {\Phi(N)}$$773$
Bob to send her a message $m$ uses the public keys of Alice, $N$ ed $e$, and computes the power $c = m^e \pmod N$ and sends $c$ through a public channel.$c$
$c \equiv m^e \pmod N = 1977^5 \pmod {2021} = $$1418$
Alice and only Alice knows the secret key $d$ and may now decipher $m$ simply computing the inverse power.$m$
$m \equiv c^d \pmod N= 1418^{773} \pmod {2021} = $$1977$
Obviously if somebody should be able to find the two factors of $N$, $p$ and $q$, or, equivalentemente, to compute $\Phi(N)$, he could compute the exponent $d$ and decipher the message.