Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

С чего начать? Python

vadim solovjev Ученик (84), на голосовании 5 лет назад
""Encode and decode Caesar cipher."""
import shift as shift

def encode(message: str, shift: int, alphabet: str) -> str:
"""
Encode the given message using the Caesar cipher principle.

:param message: The string to be encoded.
:param shift: Determines the amount of symbols to be shifted by.
:param alphabet: Determines the symbols in use. Defaults to the standard latin alphabet.
:return: Encoded string.
"""

shift

def decode(message: str, shift: int, alphabet: str) -> str:
"""
Decode the given message already encoded with the caesar cipher principle.

:param message: The string to be decoded.
:param shift: Determines the amount of symbols to be shifted by.
:param alphabet: Determines the symbols in use. Defaults to the standard latin alphabet.
:return: Decoded string.
"""

if __name__ == "__main__":
# simple tests
print(encode("hello", 1)) # ifmmp
print(decode("ifmmp", 1)) # hello

# WRITE THE REMAINING EXAMPLES YOURSELF!

# larger shift

# negative shift

# shift > alphabet.length

# case sensitivity

# misc symbols (.,:; etc.)
# ...
Голосование за лучший ответ
Похожие вопросы