Files
python/exercises/practice/rotational-cipher/.meta/example.py
Job van der Wal 37e518470a Let's try again.
2021-11-23 08:48:42 -08:00

16 lines
460 B
Python

from string import ascii_lowercase, ascii_uppercase
ALPHA_LEN = len(ascii_lowercase)
def rotate(message, key):
coded_message = ''
for char in message:
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