RSA (Asymmetric Encryption): Uses two different keys - a public key for encryption and a private key for decryption. This solves the key distribution problem of symmetric encryption.
⚠ Educational Demo Only: This uses small numbers for learning. Real RSA uses primes with hundreds of digits!
Step 1: Generate RSA Keys
Choose two prime numbers to generate your public and private keys. The math behind RSA is shown step-by-step.
RSA Key Generation Process:
1. Choose two prime numbers: p and q
2. Calculate n = p × q (part of both keys)
3. Calculate φ(n) = (p-1) × (q-1)
4. Choose e (public exponent, commonly 65537 or small prime)
5. Calculate d (private exponent) where (d × e) mod φ(n) = 1
Public Key: (e, n) - Share this freely Private Key: (d, n) - Keep this secret!
Step 2: Encrypt a Message
Anyone with the public key can encrypt a message. Only the holder of the private key can decrypt it.
How it works:
• Text is converted to numbers (A=01, B=02, etc.)
• Each number is encrypted: ciphertext = (plaintext^e) mod n
• Only someone with the private key can decrypt it
Encrypted Message (Ciphertext):
Step 3: Decrypt a Message
Only the holder of the private key can decrypt messages encrypted with the public key.
How it works:
• Each encrypted number is decrypted: plaintext = (ciphertext^d) mod n
• Numbers are converted back to text
• This only works with the correct private key