Files
python/exercises/practice/rotational-cipher/.meta/example.py

16 lines
460 B
Python
Raw Normal View History

2021-11-23 14:05:17 +01:00
from string import ascii_lowercase, ascii_uppercase
ALPHA_LEN = len(ascii_lowercase)
def rotate(message, key):
2021-11-23 14:05:17 +01:00
coded_message = ''
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]
coded_message += char
return coded_message