-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (53 loc) · 1.86 KB
/
Copy pathmain.py
File metadata and controls
66 lines (53 loc) · 1.86 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import random
import string
def encrypt(plain_text, key, chars):
cipher_text = ""
for letter in plain_text:
if letter in key:
index = key.index(letter)
cipher_text += chars[index]
else:
cipher_text += letter
return cipher_text
def decrypt(cipher_text, key, chars):
plain_text = ""
for letter in cipher_text:
if letter in chars:
index = chars.index(letter)
plain_text += key[index]
else:
plain_text += letter
return plain_text
def main():
chars = " " + string.punctuation + string.digits + string.ascii_letters +"ğüşiöçıĞÜŞİÖÇI"
chars = list(chars)
key = chars.copy()
random.shuffle(key)
cr = True
print("******************************************")
print("Welcome to Encryption and Decryption tool ")
print("******************************************")
while cr :
print("If you wanna Encrypt your message press E ")
print("If you wanna Decrypt your message press D ")
print("If you wanna Quit press Q")
option = input("(E/D/Q) ").upper()
#Encrypt
if option == "E":
plain_text = input("Enter a message to encrypt: ")
encrypted = encrypt(plain_text, key, chars)
print(f"Original message : {plain_text}")
print(f"Encrypted message : {encrypted}")
#Decrypt
elif option == "D":
cipher_text = input("Enter a message to decrypt: ")
decrypted = decrypt(cipher_text, key, chars)
print(f"Encrypted message : {cipher_text}")
print(f"Original message : {decrypted}")
elif option == "Q":
print("Bye Bye")
cr = False
else:
print("Invalid input")
if __name__ == "__main__":
main()