This repository provides basic tools to demonstrate RSA public-key cryptography using Python and the cryptography library.
You can:
- Generate public/private key pairs.
- Encrypt a plaintext file using a public key.
- Decrypt it back using the private key.
Install the required Python package:
pip install cryptographyThis section explains, step-by-step, how to use the RSA encryption and decryption scripts in this project — designed for beginner-level computer science students learning cryptography.
Plain text is a normal, readable message. For example:
Meet me at 5 PM near the library.We call this "plain text" because it's not hidden or protected in any way.
We encrypt messages to protect them from being read by anyone except the intended recipient.
Encryption turns plain text into cipher text — a scrambled, unreadable format that looks like random letters and numbers.
Great question! 🔑
In public-key cryptography (like RSA), we use two keys:
- A public key: This can be shared with everyone — even strangers.
- A private key: This is kept secret and never shared.
To send a secure message:
- You encrypt the message using the recipient's public key.
- Only the person with the matching private key can decrypt and read the message.
💡 Think of the public key like a locked mailbox:
Anyone can drop a message inside, but only the owner with the private key can open it.
This script creates a 2048-bit RSA key pair and saves them to a keys/ directory.
python3 RSA_key_generated.py🔧 Output:
- keys/public_key.pem – Public key
- keys/private_key.pem – Private key
💡 Remember, this key is pairing.
- First, create a text file with a message:
echo "This is a secret mission." > message.txt- Then, encrypt the file using the recipient's public key:
python3 do_encrypt.py -i message.txt -o encrypted.txt -pubkey keys/public_key.pem- -i = input (plain text file)
- -o = output (cipher text file)
- -pubkey = path to the recipient’s public key (for the sake of example, we can use public key that we've create before)
Only the person with the matching private key can unlock the message.
python3 do_decrypt.py -i encrypted.txt -o decrypted.txt -privkey keys/private_key.pem- -i = input (cipher text file)
- -o = output (decrypted plain text)
- -privkey = path to your private key
Now, decrypted.txt will contain the original message.
- ✍️ Plain text = your original message
- 🔒 Cipher text = encrypted message
- 🔑 Public key = used to encrypt (can be shared)
- 🔐 Private key = used to decrypt (must be secret)
This is the foundation of secure communication on the internet — used in messaging apps, banking, websites (HTTPS), and more.
Happy encrypting! 🔐✨