Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Standard solution in Clear category for Scytale Encryption by igharok
from typing import Optional
def scytale_decipher(ciphertext: str, crib: str) -> Optional[str]:
list_answers = []
str_answer = None
for d in range(2, len(ciphertext)):
str_res = ''
for i in range(d):
str_res = str_res + ''.join(ciphertext[i::d])
if crib in str_res:
list_answers.append(str_res)
if (len(list_answers) == 1):
str_answer = list_answers[0]
return str_answer
if __name__ == "__main__":
print("Example:")
print(scytale_decipher("aaaatctwtkdn", "dawn"))
# These "asserts" are used for self-checking and not for an auto-testing
assert scytale_decipher("aaaatctwtkdn", "dawn") == "attackatdawn"
assert scytale_decipher("hdoeerlallrdow", "world") == "hellodearworld"
assert (
scytale_decipher("totetshpmeecisendysescwticsriasraytlaegphet", "sicret")
== None
), "Crib is not in plaintext"
assert (
scytale_decipher("aaaatctwtkdn", "at") == None
), "More than one possible decryptions"
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 13, 2024