-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCipherOptimized.py
More file actions
21 lines (21 loc) · 905 Bytes
/
CipherOptimized.py
File metadata and controls
21 lines (21 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
letters = ['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']
text=input("Enter your message\n").lower()
shift=int(input("enter the shift number\n"))
direction=input("type'e' to encrypt or 'd' to deccrypt\n").lower()
def decrypt_encrypt(text,shift,direction):
cypher_text=''
for i in text:
old_position=letters.index(i)
if direction=="e":
new_position=old_position+shift
if new_position>len(letters):
new_position-=len(letters)
elif direction=="d":
new_position=old_position-shift
new_letter=letters[new_position]
cypher_text+=new_letter
print(f"the new Message is :\t{cypher_text}")
if (direction !="d") and (direction!="e"):
print("INVALID ENTRY")
else:
decrypt_encrypt(text,shift,direction)