From ef038ac4b67ed795ca2f3d180a9466d1e596cc99 Mon Sep 17 00:00:00 2001 From: owengavi2 Date: Tue, 14 Apr 2026 19:52:22 -0400 Subject: [PATCH] Writing my own code helped me understand and solve the problem. In Checkpoint 1, writing the code itself was a means of solving the problem. Figuring out what worked and what didn't work led to conceptual understanding of the problem. Honestly, I was fairly confidant in my oringinal approach to checkpoint 1, as I have solved similar problems in the past. For checkpoint 2, I assigned each character its value in the ASCII, since the first printable character at 32 and ends at the last printable character at 126. We look for reapeated character chunks like in the Kasiski examination method, and find the distance between them. In this case it was 42. Then possible periods are factors of 42. Testing each of these, the only one that spelled a valid english word was a period of 6, giving the word python. Then, when we use that key we can decrpyt the strings using frequency analysis. --- .envrc | 1 + answers.md | 14 +++++++++----- caesar_cracker.py | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 .envrc create mode 100644 caesar_cracker.py diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..4a96c22 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +source .venv/bin/activate \ No newline at end of file diff --git a/answers.md b/answers.md index f125e69..ab9b74a 100644 --- a/answers.md +++ b/answers.md @@ -4,22 +4,26 @@ 0. `secrets/secret0.txt` is encrypted using a Caesar Cipher. What is its secret number? - +78 1. `secrets/secret1.txt` is encrypted using a Caesar Cipher. What is its secret number? - +1 2. `secrets/secret2.txt` is encrypted using a Caesar Cipher. What is its secret number? - +44 3. `secrets/secret3.txt` is encrypted using a Caesar Cipher. What is its secret number? - +59 4. `secrets/secret4.txt` is encrypted using a Caesar Cipher. What is its secret number? - +32 ## Checkpoint 2 5. What is the polyalphabetic secret word? +PYTHON + 6. Decrypt this message, which was encrypted using the same secret word: "EbZhdaV[h^bTpchhQnhig]X[VmhhRP]ftXVnRfjVY]fgtO_X](" + +The treasure is a worthless ball of aluminum foil. \ No newline at end of file diff --git a/caesar_cracker.py b/caesar_cracker.py new file mode 100644 index 0000000..d449c47 --- /dev/null +++ b/caesar_cracker.py @@ -0,0 +1,24 @@ +from easybits import Bits +from collections import Counter +from ciphers.caesar import CaesarCipher + +def crack_caesar(ciphertext): + counted = Counter(ciphertext) + charlist = list(counted.keys()) + commonchar = charlist[0] + for char in charlist: + if counted[char] > counted[commonchar]: + commonchar = char + return Bits(commonchar).int - Bits(" ").int + +with open("secrets/secret4.txt") as f: + ciphertext = f.read() + + + +secret = crack_caesar(ciphertext) +cipher = CaesarCipher(secret) +plaintext = cipher.decrypt(ciphertext) + +print(secret) +print(plaintext)