From 0f971d875587add60d9c749ca280046bc9549ce0 Mon Sep 17 00:00:00 2001 From: Rene Date: Fri, 28 Aug 2026 09:11:03 +0200 Subject: [PATCH] docs: add docstrings and doctests to simple_substitution_cipher --- ciphers/simple_substitution_cipher.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ciphers/simple_substitution_cipher.py b/ciphers/simple_substitution_cipher.py index 291a9bccd771..3c6898c7b1ee 100644 --- a/ciphers/simple_substitution_cipher.py +++ b/ciphers/simple_substitution_cipher.py @@ -22,6 +22,16 @@ def main() -> None: def check_valid_key(key: str) -> None: + """ + Check if the key is valid (contains all 26 letters of the alphabet exactly once). + Exits the program if the key is invalid. + + >>> check_valid_key('LFWOAYUISVKMNXPBDCRJTQEGHZ') + >>> check_valid_key('INVALIDKEY') + Traceback (most recent call last): + ... + SystemExit: Error in the key or symbol set. + """ key_list = list(key) letters_list = list(LETTERS) key_list.sort() @@ -69,6 +79,13 @@ def translate_message(key: str, message: str, mode: str) -> str: def get_random_key() -> str: + """ + Generate a random substitution cipher key. + + >>> random.seed(0) + >>> get_random_key() + 'OAXSGFHKWUECVDRLTJZPQIBNYM' + """ key = list(LETTERS) random.shuffle(key) return "".join(key)