From 253a2f62acb93ceda3044058cac15a5ee497b612 Mon Sep 17 00:00:00 2001 From: JISAUAY Date: Tue, 23 Sep 2025 13:26:56 -0500 Subject: [PATCH] updated readme and added some new prints to part 1 / 2 --- README.md | 28 ++++++++++++++++++++++++++++ part1/alice.py | 2 ++ part1/bob.py | 2 ++ part2/alice.py | 2 ++ part2/bob.py | 2 ++ 5 files changed, 36 insertions(+) diff --git a/README.md b/README.md index e69de29..25207c7 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,28 @@ +# About + +This is the Cryptography homework 3. + +# Usage + +## Installation + +Please install `pycryptodome` using Python 3.10. + +## Part 1 + +First run `alice.py` and input the message. +Run `bob.py` to decrypt the message. + +## Part 2 + +Run `bob.py` to generate bob's public and private keys. +Run `alice.py` and enter a message. +Run `bob.py` to decrypt the message. + +## Part 3 + +Run `speed-test.py` or speed-test-nokey.py`. + +The difference between the two is that nokey doesn't generate a new key for each encryption and decryption. + + diff --git a/part1/alice.py b/part1/alice.py index 13c4c5c..d7a92ef 100644 --- a/part1/alice.py +++ b/part1/alice.py @@ -26,6 +26,8 @@ cipher = AES.new(aes_key, AES.MODE_CBC, iv=b'0'*16) ciphertext = cipher.encrypt(plaintext) +print(f'Ciphertext: {ciphertext}') + with open('ctext', 'wb') as f: f.write(ciphertext) diff --git a/part1/bob.py b/part1/bob.py index 5a56db1..917a8da 100644 --- a/part1/bob.py +++ b/part1/bob.py @@ -12,6 +12,8 @@ cipher = AES.new(aes_key, AES.MODE_CBC, iv=b'0'*16) with open('ctext', 'rb') as f: ciphertext = f.read() +print(f'Ciphertext: {ciphertext}') + plaintext = unpad(cipher.decrypt(ciphertext), 16).decode() print(f'Plaintext: {plaintext}') diff --git a/part2/alice.py b/part2/alice.py index 63e6329..ae13f57 100644 --- a/part2/alice.py +++ b/part2/alice.py @@ -14,6 +14,8 @@ 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) diff --git a/part2/bob.py b/part2/bob.py index 52cd9ff..e29bb8c 100644 --- a/part2/bob.py +++ b/part2/bob.py @@ -31,6 +31,8 @@ with open("bob_private.pem", "rb") as f: with open("ctext", "rb") as f: ciphertext = f.read() +print(f'Ciphertext: {ciphertext}') + cipher = PKCS1_OAEP.new(private_key) # Decrypt