Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First: slice solution in Clear category for Scytale Encryption by keromage
from typing import Optional
from math import ceil
def scytale_decipher(ciphertext: str, crib: str) -> Optional[str]:
num = len(ciphertext) + 1
chrs_list = [i for i in ciphertext]
answer = []
for j in range(num + 1):
temp = []
for i in range(j):
temp += chrs_list[i : j * (ceil(num / j) - 1) + i + 1 : j]
guess = "".join(temp)
if crib in guess:
answer.append(guess)
if len(answer) != 1:
return None
else:
return answer[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. 6, 2022
Comments: