"""Caesar Cipher improved.

Rewritten as function with wrapper functions for importing.

Note:
    Contains spoilers from Chapter 5 (caesarCipher) and Chapter 7 (functions)
"""

from pythontutorials.books.CrackingCodesWithPython.Chapter01.constants import SYMBOLS


def decryptMessage(key: int, message: str) -> str:
    """Decrypts encrypted caesar cipher.

    Wrapper function that calls caesarCipher() to decrypt given message with given key.

    Args:
        key: Key to use to decrypt message.
        message: Message to decrypt.

    Returns:
        Returns decrypted string.
    """
    return caesarCipher(key, message, "decrypt")


def encryptMessage(key: int, message: str) -> str:
    """Encrypts message with caesar cipher.

    Wrapper function that calls caesarCipher() to encrypt given message with given key.

    Args:
        key: Key to use to encrypt message.
        message: Message to encrypt.

    Returns:
        Returns encrypted string.
    """
    return caesarCipher(key, message, "encrypt")


def caesarCipher(key: int, message: str, mode: str) -> str:
    """Implement caesar cipher.

    Encrypts or decrypts given message with given key depending on given mode.

    Args:
        key: Key to use for [de|en]cryption.
        message: Message to encrypt/decrypt.
        mode: Specifies encryption or decryption.

    Returns:
        translated: Encrypted/decrypted message string.

    Example:
        >>> caesarCipher(4, 'IMPIETY: YOUR IRREVERENCE TOWARD MY DEITY.', 'encrypt')
        'MQTMIXc:AcSYVAMVVIZIVIRGIAXSaEVHAQcAHIMXcD'
    """

    # Store the encrypted/decrypted form of the message:
    translated = ''

    for symbol in message:
        # Note: Only symbols in the SYMBOLS string can be encrypted/decrypted.
        if symbol in SYMBOLS:
            symbolIndex = SYMBOLS.find(symbol)

            # Perform encryption/decryption:
            if mode == 'encrypt':
                translatedIndex = symbolIndex + key
            elif mode == 'decrypt':
                translatedIndex = symbolIndex - key

            # Handle wraparound, if needed:
            if translatedIndex >= len(SYMBOLS):
                translatedIndex -= len(SYMBOLS)
            elif translatedIndex < 0:
                translatedIndex += len(SYMBOLS)

            translated += SYMBOLS[translatedIndex]
        else:
            # Append the symbol without encrypting/decrypting:
            translated += symbol

    return translated

@@ -558,25 +558,25 @@
     
-Returns decrypted
+Decrypted message
  str
@@ -941,25 +941,25 @@
     
-Returns encrypted
+Encrypted message
  str
@@ -1370,20 +1370,8 @@
     
- translated:
  Enc
@@ -1417,16 +1417,122 @@
 xample:%0A
+        %3E%3E%3E from pythontutorials.books.CrackingCodesWithPython.Chapter01.caesarCipher import caesarCipher%0A
         

Update caesarCipher.py reworded docstrings and added import to docstring example