Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Scytale Encryption by freixodachamorra
from typing import Optional
def scytale_decipher(ciphertext: str, crib: str) -> Optional[str]:
def treid(ciphertext, number):
stri = []
for i in range(number):
stri.append("".join([ciphertext[j] for j in range(i, len(ciphertext), number)]))
return "".join(stri)
solution = []
for num in range(len(ciphertext)):
deciph = treid(ciphertext, num)
if crib in deciph:
solution.append(deciph)
if len(solution) != 1:
return None
else:
return solution[0]
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!")
Feb. 3, 2022