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.
This commit is contained in:
owengavi2
2026-04-14 19:52:22 -04:00
parent add8137184
commit ef038ac4b6
3 changed files with 34 additions and 5 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
source .venv/bin/activate

View File

@@ -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.

24
caesar_cracker.py Normal file
View File

@@ -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)