-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceaser.py
More file actions
30 lines (28 loc) · 1.12 KB
/
Copy pathceaser.py
File metadata and controls
30 lines (28 loc) · 1.12 KB
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
29
30
alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphabet_lower = "abcdefghijklmnopqrstuvwxyz"
def cipEncode(plaintext, shift=3):
ciphertext = []
for char in plaintext:
if char in alphabet_upper:
i = alphabet_upper.index(char)
letter = alphabet_upper[(i + shift) % len(alphabet_upper)]
elif char in alphabet_lower:
i = alphabet_lower.index(char)
letter = alphabet_lower[(i + shift) % len(alphabet_lower)]
else:
letter = char # Non-alphabet characters are unchanged
ciphertext.append(letter)
return ''.join(ciphertext)
def cipDecode(ciphertext, shift=-3):
plaintext = []
for char in ciphertext:
if char in alphabet_upper:
i = alphabet_upper.index(char)
letter = alphabet_upper[(i + shift) % len(alphabet_upper)]
elif char in alphabet_lower:
i = alphabet_lower.index(char)
letter = alphabet_lower[(i + shift) % len(alphabet_lower)]
else:
letter = char # Non-alphabet characters are unchanged
plaintext.append(letter)
return ''.join(plaintext)