-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCeaser_Encoder_Decoder.py
More file actions
33 lines (26 loc) · 1.01 KB
/
Ceaser_Encoder_Decoder.py
File metadata and controls
33 lines (26 loc) · 1.01 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
31
32
33
def encrypt(text, shift):
for i in range(len(text)):
word_list=list(text)
letter_index=alphabet.index(text[i])
letter_index=letter_index+shift
word_list[i]=alphabet[letter_index]
text=''.join(word_list)
print(text)
def decrypt(text, shift):
for i in range(len(text)):
word_list=list(text)
letter_index=alphabet.index(text[i])
letter_index=abs(letter_index-shift)
word_list[i]=alphabet[letter_index]
text=''.join(word_list)
print(text)
def ceaser(text, shift, direction):
if direction=="encode":
encrypt(text, shift)
elif direction=="decrypt":
decrypt(text, shift)
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']
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
ceaser(text, shift, direction)