forked from bhanuprathap2000/pythonprograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceaser_encoding_decoding.py
More file actions
30 lines (24 loc) · 992 Bytes
/
ceaser_encoding_decoding.py
File metadata and controls
30 lines (24 loc) · 992 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
29
30
alphabets=list("abcdefghijklmnopqrstuvwxyz")
def ceaser(direction,plain_text,shift_amount):
end_text=""
for char in plain_text:
if char in alphabets:
if direction=="encode":
position=alphabets.index(char)
new_position=(position+shift_amount)%25
elif direction=="decode":
position=alphabets.index(char)
new_position=(position-shift_amount)%25
end_text+=alphabets[new_position]
else:
end_text+=char
print(end_text)
repeat=True
while repeat:
ceaser_direction=input("Type encode, for encoding and decode, for decoding\n")
text=input("Enter the text\n");
shift=int(input("Enter the shift number\n"))
ceaser(direction=ceaser_direction,plain_text=text,shift_amount=shift)
again=input("Yes for reapeating no for exit\n")
if (again=="no"):
repeat=False