Let’s walk through a very simple example of RSA encryption and decryption using small numbers, perfect for understanding the core concept.
⚠️ Note: This is not secure for real-world use. It’s for educational purposes only.
🔑 Step 1: Key Generation
- Choose two prime numbers:
p = 3
q = 11
- Compute:
n = p × q = 3 × 11 = 33
φ(n) = (p - 1)(q - 1) = 2 × 10 = 20
- Choose a public exponent:
e = 3
(must be coprime with φ(n))
- Compute the private exponent
d
:- Find
d
such that(d × e) mod φ(n) = 1
- Try
d = 7
:(7 × 3) mod 20 = 21 mod 20 = 1 ✅
- Find
Resulting Keys:
- Public Key:
(e = 3, n = 33)
- Private Key:
(d = 7, n = 33)
📤 Step 2: Alice Sends a Message to Bob
Alice wants to send the number 4
to Bob securely.
🔐 Step 3: Encryption (Using Bob’s Public Key)
Formula:
cipher = (message^e) mod n
Calculation:
cipher = (4^3) mod 33
= 64 mod 33
= 31
Encrypted Message: 31
🔓 Step 4: Decryption (Using Private Key)
Formula:
message = (cipher^d) mod n
Calculation:
message = (31^7) mod 33
= 4
Bob successfully recovers the original message: 4 ✅
🧠 Visual Diagram of the Process (Text-Based)
[Alice]
|
| Message: 4
v
Encrypt with Public Key (e=3, n=33)
|
v
Ciphertext: 31
|
v
[Bob]
|
Decrypt with Private Key (d=7, n=33)
|
v
Decrypted Message: 4
📌 Summary
Step | Value |
---|---|
Primes | p = 3, q = 11 |
n | 33 |
φ(n) | 20 |
Public Key | (3, 33) |
Private Key | (7, 33) |
Message | 4 |
Encrypted | 31 |
Decrypted | 4 ✅ |
Leave a Comment