forked from Berat-O/Python_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText_encryption.py
More file actions
45 lines (31 loc) · 916 Bytes
/
Text_encryption.py
File metadata and controls
45 lines (31 loc) · 916 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#encryption programming
import random
import string
chars = " " + string.punctuation + string.digits + string.ascii_letters
chars=list(chars)
key = chars.copy()
random.shuffle(key)
#print(chars)
#print(key)
#ENCRYPT
plain_text = input("Enter a message to encrypt: ")
if not plain_text.isalpha():
print("Error: Only alphabets are allowed!")
exit()
cipher_text = ""
for letter in plain_text:
index = chars.index(letter)
cipher_text += key[index]
print(f"original message : {plain_text}")
print(f"encrypted message : {cipher_text}")
#decrypt
cipher_text = input("Enter a message to decrypt: ")
if not cipher_text.isalpha():
print("Error: Only alphabets are allowed!")
exit()
plain_text = ""
for letter in cipher_text:
index = key.index(letter)
plain_text += chars[index]
print(f"encrypted message : {cipher_text}")
print(f"original message : {plain_text}")