Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Nested for loops solution in Clear category for Scytale Encryption by kkkkk
from typing import Optional
def scytale_decipher(ciphertext: str, crib: str) -> Optional[str]:
"""Return deciphered text or None if crib isn't found just once in text."""
match_found = None
for line_len in range(2, len(ciphertext)):
deciphered_text = []
for start_idx in range(line_len):
deciphered_text.append(ciphertext[start_idx::line_len])
if crib in ''.join(deciphered_text):
if match_found:
return None
else:
match_found = ''.join(deciphered_text)
return match_found
Feb. 9, 2022