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
39 lines (25 loc) · 739 Bytes
/
Text_encryption.py
File metadata and controls
39 lines (25 loc) · 739 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
#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: ")
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: ")
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}")