generated from mwc/lab_encryption
34 lines
781 B
Python
34 lines
781 B
Python
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|