ciphers.skytale_cipher ====================== .. py:module:: ciphers.skytale_cipher .. autoapi-nested-parse:: Scytale (Skytale) transposition cipher. A classical transposition cipher used in ancient Greece. The sender wraps a strip of parchment around a rod (scytale) and writes the message along the rod. The recipient with a rod of the same diameter can read the message. Reference: https://en.wikipedia.org/wiki/Scytale Functions here keep characters as-is (including spaces). The key is a positive integer representing the circumference count (number of rows). >>> encrypt("WE ARE DISCOVERED FLEE AT ONCE", 3) 'WA SVEFETNERDCEDL C EIOR EAOE' >>> decrypt('WA SVEFETNERDCEDL C EIOR EAOE', 3) 'WE ARE DISCOVERED FLEE AT ONCE' Edge cases: >>> encrypt("HELLO", 1) 'HELLO' >>> decrypt("HELLO", 1) 'HELLO' >>> encrypt("HELLO", 5) # key equals length 'HELLO' >>> decrypt("HELLO", 5) 'HELLO' >>> encrypt("HELLO", 0) Traceback (most recent call last): ... ValueError: Key must be a positive integer >>> decrypt("HELLO", -2) Traceback (most recent call last): ... ValueError: Key must be a positive integer Functions --------- .. autoapisummary:: ciphers.skytale_cipher.decrypt ciphers.skytale_cipher.encrypt Module Contents --------------- .. py:function:: decrypt(ciphertext: str, key: int) -> str Decrypt Scytale ciphertext. Reconstruct rows by their lengths and interleave by columns. :param ciphertext: Encrypted string :param key: Positive integer number of rows :return: Decrypted plaintext :raises ValueError: if key <= 0 .. py:function:: encrypt(plaintext: str, key: int) -> str Encrypt plaintext using Scytale transposition. Write characters around a rod with `key` rows, then read off by rows. :param plaintext: Input message to encrypt :param key: Positive integer number of rows :return: Ciphertext string :raises ValueError: if key <= 0