Files

23 lines
525 B
Python

from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
# Read Bob's public key
with open("bob_public.pem", "rb") as f:
public_key = RSA.import_key(f.read())
# Get the message from the command line
message = input("Enter a message: ").encode()
# Create a cipher object using Bob's public key
cipher = PKCS1_OAEP.new(public_key)
# Encrypt the message
ciphertext = cipher.encrypt(message)
print(f'Ciphertext: {ciphertext}')
# Write the ciphertext
with open("ctext", "wb") as f:
f.write(ciphertext)