-
Notifications
You must be signed in to change notification settings - Fork 0
/
CaeserCiphercode.py
44 lines (38 loc) · 1.42 KB
/
CaeserCiphercode.py
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
31
32
33
34
35
36
37
38
39
40
41
42
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
def encryption(plain_text, shift_key):
cipher_text = ""
for char in plain_text:
if char in alphabet:
position = alphabet.index(char)
new_position = (position + shift_key) % 26
cipher_text += alphabet[new_position]
else:
cipher_text += char
print(f"heres is the text after encryption:{cipher_text}")
def decryption(shift_key, cipher_text):
plain_text = ""
for char in cipher_text:
if char in alphabet:
position = alphabet.index(char)
new_position = (position - shift_key) % 26
plain_text += alphabet[new_position]
else:
plain_text += char
print(f"heres is the text after decryption:{plain_text}")
wanna_end =False
while not wanna_end:
what_to_do = input("type 'encrypt' for encryption, type 'decrypt' for decryption:\n")
text = input("type your message:\n")
shift = int(input("enter shift key:\n"))
if what_to_do == "encrypt":
encryption(text, shift)
elif what_to_do == "decrypt":
decryption(text, shift)
play_again = input("type yes to continue, type no to stop:")
if play_again == 'no':
wanna_end = true
print("have a nice day bye")
else:
print("lets go again")