Encryption
Encryption is the process of encoding a message such that only authorized parties can access it. Encryption has existed for a long time, with one famous example being the Caesar cipher. This cipher involved shifting each letter in the message by a fixed amount. If one wanted to encode the message 'attack' with a right shift of 3, the result would be 'dwwdfn.'
Types of Encryption
There are two kinds of encryption, symmetric and asymmetric encryption. For simplicity, let's consider encrypting a message as putting a lock on it and decrypting as unlocking it with a key. For symmetric encryption, both parties share the secret key with each other before sending messages. Then, in order to send an encrypted message, one party locks the message and sends it openly to the other party. Since both have the same key, the other party can unlock it and obtain the unencrypted message. However, what if the two parties can never meet and share the secret key in the first place? This is where asymmetric encryption comes in.
For asymmetric encryption, also known as public key encryption, one party who we call party A leaves their lock out for people to use. If another party, party B, wanted to send a message to party A, they use party A's lock and secure or encrypt the package and send it. Party A keeps the key to the lock hidden so no one else can unlock or decrypt the package.
Public-Key Encryption Animation
This animation shows how public-key encryption works.
RSA Encryption
RSA is used to generate the key and the lock used in asymmetric encryption. RSA stands for Ron Rivest, Adi Shamir and Leonard Adleman, the first people to publicly describe it. The strength of RSA encryption lies on the difficulty of factoring large numbers.
We can see from this animation that the time it takes to multiply large numbers stays constant, while the time it takes to factor large numbers increases exponentially. With large enough numbers, it would take years or even decades to factor them.
Generating the Modulus N
To begin RSA encryption, we must first generate two large primes. The larger the prime, the harder the encryption will be to crack.
Both p and q are not prime.
p is not prime.
q is not prime.
$N = p \cdot q$:  
$N$ is the modulus used when encrypting and decrypting.
Calculating Φ(N)
Then we need to calculate $\Phi(N)$. $\Phi(N) = (p-1)\cdot (q-1)$.
So $\Phi(N) =$
$\Phi(N)$ is used to create the public and private keys.
Obtaining the Encryption and Decryption Keys
Now, we define our encryption key $e$ and our decryption key $d$ to satisfy the equation $d\cdot e \equiv 1 \bmod \Phi(N)$, where $e$ must be coprime with $\Phi(N)$. In other words, $d\cdot e = k \cdot \Phi(N) + 1$, for some $k > 0$.
Now, choose $e$, such that $e$ is coprime to $\Phi(N)$. In practice, $e$ is usually $2^{16}+1 = 65537$.
$e$ is not coprime to $\Phi(N)$.
$d$:
One interesting question that arises is this: why are we using $\Phi(N)$ as our modulus for calculating the encryption and decryption key? The answer is quite simple: it is hard to calculate $\Phi(N)$. Try it yourself! Without knowing that $N = p\cdot q$ and therefore $\Phi(N) = (p-1)\cdot(q-1)$, $\Phi(N)$ is hard to calculate. Therefore, we use $\Phi(N)$ because we can calculate it easily and use it to generate the keys, but no one else can.
Message Encryption
Now we can finally try encrypting and decrypting a message.
We can obtain the cipher text $c$, our encrypted message, by doing the following calculation: $c = m^e \bmod n$.
This means that we need to convert our message in a number form.
Numerical conversion of message:
Encrypted message:
To decrypt the message, we just do the opposite: $m = c^d \bmod n$.
Decrypted numerical message:
Decrypted message:
Full RSA Encryption Animation
Here is an animation that shows the entire process of RSA encryption.