commit 640aa3e9aff14d017cfdbab6a5958a0a394c80cc Author: Kaushik Narayan R Date: Wed Jan 31 15:41:22 2024 -0700 1.1 done also initial commit diff --git a/hw1.1/1a.py b/hw1.1/1a.py new file mode 100644 index 0000000..337b95b --- /dev/null +++ b/hw1.1/1a.py @@ -0,0 +1,10 @@ +with open("3/forstudents/a/ciphertext.bin", "rb") as cipher_file, open( + "3/forstudents/a/key.bin", "rb" +) as key_file: + cipher_content = cipher_file.read() + key_content = key_file.read() + print( + (( + int.from_bytes(cipher_content, "big") ^ int.from_bytes(key_content, "big") + ).to_bytes(max(len(cipher_content), len(key_content)), "big")).decode() + ) diff --git a/hw1.1/1b.py b/hw1.1/1b.py new file mode 100644 index 0000000..4362881 --- /dev/null +++ b/hw1.1/1b.py @@ -0,0 +1,19 @@ +with open("3/forstudents/b/ciphertext1.bin", "rb") as cipher1_file, open( + "3/forstudents/b/ciphertext2.bin", "rb" +) as cipher2_file, open("3/forstudents/b/plaintext1.txt", "r") as plain_unknown_file: + cipher1_content = cipher1_file.read() + cipher2_content = cipher2_file.read() + plain_unknown_content = plain_unknown_file.read() + + possible_key = ( + int.from_bytes(cipher1_content, "big") + ^ int.from_bytes(bytes(plain_unknown_content, "utf-8"), "big") + ).to_bytes(max(len(cipher1_content), len(plain_unknown_content)), "big") + print( + ( + ( + int.from_bytes(cipher2_content, "big") + ^ int.from_bytes(possible_key, "big") + ).to_bytes(max(len(cipher2_content), len(possible_key)), "big") + ).decode("latin-1") + ) diff --git a/hw1.1/3/forstudents/a/ciphertext.bin b/hw1.1/3/forstudents/a/ciphertext.bin new file mode 100644 index 0000000..9437c33 Binary files /dev/null and b/hw1.1/3/forstudents/a/ciphertext.bin differ diff --git a/hw1.1/3/forstudents/a/key.bin b/hw1.1/3/forstudents/a/key.bin new file mode 100644 index 0000000..617178a Binary files /dev/null and b/hw1.1/3/forstudents/a/key.bin differ diff --git a/hw1.1/3/forstudents/b/ciphertext1.bin b/hw1.1/3/forstudents/b/ciphertext1.bin new file mode 100644 index 0000000..22f6bbd Binary files /dev/null and b/hw1.1/3/forstudents/b/ciphertext1.bin differ diff --git a/hw1.1/3/forstudents/b/ciphertext2.bin b/hw1.1/3/forstudents/b/ciphertext2.bin new file mode 100644 index 0000000..857bb73 Binary files /dev/null and b/hw1.1/3/forstudents/b/ciphertext2.bin differ diff --git a/hw1.1/3/forstudents/b/plaintext1.txt b/hw1.1/3/forstudents/b/plaintext1.txt new file mode 100644 index 0000000..8307de3 --- /dev/null +++ b/hw1.1/3/forstudents/b/plaintext1.txt @@ -0,0 +1 @@ +-out-the-important-messages-ever-more-surely--Bratton-and-Kramer-hustled-from-place-to-place-with-their-locked-briefcases--MAGIC-gushed-forth-in-profusion--So-effectively-did-the-cryptanalytic-agencies-perform-that-Marshall-could-say-of-this--priceless-asset---this-most-complete-and-up-to-the-minute-intelligence-that-any-nation-had-ever-had-concerning-a-probable-enemy--this-necromantic-gift-of-the \ No newline at end of file