2021-11-23 14:05:17 +01:00
|
|
|
from string import ascii_lowercase, ascii_uppercase
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ALPHA_LEN = len(ascii_lowercase)
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def rotate(message, key):
|
2021-11-23 14:05:17 +01:00
|
|
|
coded_message = ''
|
2017-04-03 10:48:11 -03:00
|
|
|
for char in message:
|
2021-11-23 14:05:17 +01:00
|
|
|
if char in ascii_lowercase:
|
|
|
|
|
char = ascii_lowercase[(ascii_lowercase.index(char) + key) % ALPHA_LEN]
|
|
|
|
|
elif char in ascii_uppercase:
|
|
|
|
|
char = ascii_uppercase[(ascii_uppercase.index(char) + key) % ALPHA_LEN]
|
2017-04-03 10:48:11 -03:00
|
|
|
coded_message += char
|
|
|
|
|
return coded_message
|