-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar.py
More file actions
28 lines (26 loc) · 787 Bytes
/
caesar.py
File metadata and controls
28 lines (26 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def alphabet_position(letter):
alphabet = "abcdefghijklmnopqrstuvwxyz"
letter = letter.lower()
return alphabet.find(letter)
def rotate_character(char, rot):
alphabet = "abcdefghijklmnopqrstuvwxyz"
position = alphabet_position(char)
if char.isupper():
if char.lower() in alphabet:
position += rot
position = position % 26
return alphabet[position].upper() #addon
else:
return char
else:
if char in alphabet:
position += rot
position = position % 26
return alphabet[position] #addon
else:
return char
def encrypt(text, rot):
result = ''
for letter in text:
result += rotate_character(letter, rot)
return result