import string
_lower_cipher = string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
_upper_cipher = string.ascii_uppercase[13:] + string.ascii_uppercase[:13]
def encode(message):
"""
Encode a message from English to ROT13
Args:
message (str): the English message to encode
Returns:
str: The encoded message
Examples:
>>> encode("Secretmessage")
'Frpergzrffntr'
"""
output = []
for letter in message:
if letter in string.ascii_lowercase:
i = string.ascii_lowercase.find(letter)
output.append(_lower_cipher[i])
elif letter in string.ascii_uppercase:
i = string.ascii_uppercase.find(letter)
output.append(_upper_cipher[i])
return "".join(output)
def decode(message):
"""
Encode a message from ROT13 to English
Args:
message (str): the ROT13 message to encode
Returns:
str: The decoded message
Examples:
>>> encode("Frpergzrffntr")
'Secretmessage'
"""
output = []
for letter in message:
if letter in _lower_cipher:
i = _lower_cipher.find(letter)
output.append(string.ascii_uppercase[i])
elif letter in _upper_cipher:
i = _upper_cipher.find(letter)
output.append(string.ascii_uppercase[i])
return "".join(output)