-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.py
More file actions
32 lines (25 loc) · 730 Bytes
/
encryption.py
File metadata and controls
32 lines (25 loc) · 730 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
import random
import string
chars = " " + string.punctuation + string.digits + string.ascii_letters
chars = list(chars)
key = chars.copy()
random.shuffle(chars)
chars = "".join(chars)
print(f"chars: {key}")
print(f"key: {chars}")
# Encryption
plain_txt = input("Enter a message to encrypt: ")
cipher_txt = ""
for letter in plain_txt:
index = chars.index(letter)
cipher_txt += key[index]
print(f"Original message: {plain_txt}")
print(f"Encrypted message: {cipher_txt}")
# Decryption
cipher_txt = input("Enter a message to decrypt: ")
plain_txt = ""
for letter in cipher_txt:
index = key.index(letter)
plain_txt += chars[index]
print(f"Original message: {cipher_txt}")
print(f"Encrypted message: {plain_txt}")