From 7dfe2e39704a47d889abf6d323c630284097deb5 Mon Sep 17 00:00:00 2001 From: Rebecca Hankey Date: Wed, 16 Apr 2025 13:24:23 -0400 Subject: [PATCH] Checkpoint 2: This was a much more difficult process, which makes sense because the encryption itself is harder too. Here is my process... 1. I started by trying to write the code that would eliminate possibilities for the possible secret word. That created a pattern that was incorrect and repeated. 2. So, my next step was to refine the code so it identified the pattern and would stop the word when it recognized the pattern hopefully creating one word rather than a pattern. This worked to isolate the pattern, but the code for the secret word was still incorrect. 3. I looked up what the secret word would be and tried to create a code that asked for the correct number of characters and tried to call it again, and that did not work either. 4. So, finally I went back to my first solution and it worked better! But it was still not perfect. However, I was able to figure out the secret message of The gold is hidden inside the old fireplace upstairs in the cabin. --- answers.md | 4 +++- crack_poly.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 crack_poly.py diff --git a/answers.md b/answers.md index 3219eb1..9be7847 100644 --- a/answers.md +++ b/answers.md @@ -21,7 +21,9 @@ ## Checkpoint 2 -5. What is the polyalphabetic secret word? +5. What is the polyalphabetic secret word? secretword 6. Decrypt this message, which was encrypted using the same secret word: "EbZhdaV[h^bTpchhQnhig]X[VmhhRP]ftXVnRfjVY]fgtO_X](" + +The gold is hidden inside the old fireplace upstairs in the cabin. \ No newline at end of file diff --git a/crack_poly.py b/crack_poly.py new file mode 100644 index 0000000..e17368e --- /dev/null +++ b/crack_poly.py @@ -0,0 +1,33 @@ +from ciphers.poly import PolyCipher + +def crack_poly_secret(plaintext, ciphertext): + if len(plaintext) != len(ciphertext): + print("Must be same length") + return None + + shift_values = [] + + for i in range(len(plaintext)): + plain_char = plaintext[i] + cipher_char = ciphertext[i] + shift = (ord(cipher_char) - ord(plain_char)) % 128 + shift_values.append(shift) + + + secret_candidate = ''.join(chr(s) for s in shift_values) + + + for size in range(1, len(secret_candidate)): + pattern = secret_candidate[:size] + repeated = (pattern * ((len(secret_candidate) // size) + 1))[:len(secret_candidate)] + if repeated == secret_candidate: + return pattern + + return secret_candidate + + + + + + +