Let’s walk through a step-by-step encryption example with real numbers, keeping it simple so you see exactly what happens.
Because modern algorithms like AES or RSA use huge numbers (hundreds or thousands of bits), I’ll show you a tiny toy example using RSA, with small numbers you can follow by hand.
This will not be secure (too small), but it will demonstrate the principle perfectly.
π― RSA Example (Small Numbers)
Goal:
Encrypt and decrypt the number M = 7
π ️ STEP 1: Key Generation
✅ Choose two prime numbers:
-
p = 3
-
q = 11
✅ Compute n = p × q:
n = 3 × 11 = 33
This number n will be part of your public key and private key.
✅ Compute Euler’s totient:
✅ Choose public exponent e:
-
e must be coprime with 20.
-
Let’s pick e = 3.
Public Key = (e, n) = (3, 33)
✅ Compute private exponent d:
Find d such that:
Try d=7:
3×7=21 mod 20=1 ✅
Private Key = (d, n) = (7, 33)
π ️ STEP 2: Encryption
Message M = 7
Encryption formula:
Compute:
First compute 7³ = 343.
343 mod 33:
33×10=330 → remainder = 13.
✅ Ciphertext C = 13.
Result:
Encrypted message = 13
This is what you transmit.
π ️ STEP 3: Decryption
Decryption formula:
Compute:
- Decrypted message M = 7
Success!
π§ Why Is This Secure in Real Life?
Because with large primes (hundreds of digits), even knowing (n, e) doesn’t help you find d or factor n. It’s computationally infeasible.
This toy example used:
-
Tiny primes (3 and 11)
-
Tiny modulus (33)
But the real RSA uses:
-
2048-bit numbers (hundreds of digits long)
-
Huge exponents
π‘️ Real Life: What Happens?
1️⃣ You encrypt a symmetric key (AES key) with RSA public key.
2️⃣ Data is encrypted with the AES key (fast symmetric encryption).
3️⃣ The receiver decrypts the AES key with their private RSA key.
4️⃣ They decrypt the data.
This combination is called hybrid encryption.
✅ Recap of this RSA Example
-
Public key: (3,33)
-
Private key: (7,33)
-
Message: 7
-
Encrypted: 13
-
Decrypted: 7