🔐 RSA Public Key Cryptography – Simplified Example with Small Numbers

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

  1. Choose two prime numbers:
    • p = 3
    • q = 11
  2. Compute:
    • n = p × q = 3 × 11 = 33
    • φ(n) = (p - 1)(q - 1) = 2 × 10 = 20
  3. Choose a public exponent:
    • e = 3 (must be coprime with φ(n))
  4. 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 ✅

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 Message31


🔓 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

StepValue
Primesp = 3, q = 11
n33
φ(n)20
Public Key(3, 33)
Private Key(7, 33)
Message4
Encrypted31
Decrypted4 ✅