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 + + + + + + +