# Practical 3 – Secure Communication: Generate RSA Keys
# Install: pip install cryptography
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa

for name in ("sender", "receiver"):
    private = rsa.generate_private_key(public_exponent=65537, key_size=2048)
    public = private.public_key()
    with open(f"{name}_private_key.pem", "wb") as file:
        file.write(private.private_bytes(
            serialization.Encoding.PEM,
            serialization.PrivateFormat.TraditionalOpenSSL,
            serialization.NoEncryption(),
        ))
    with open(f"{name}_public_key.pem", "wb") as file:
        file.write(public.public_bytes(
            serialization.Encoding.PEM,
            serialization.PublicFormat.SubjectPublicKeyInfo,
        ))

print("Sender and receiver keys saved.")

# What this code does: generates RSA key pairs for the sender and receiver
# and saves each public and private key to a PEM file.
