-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncryption Algorithm in Python.py
51 lines (36 loc) · 1.21 KB
/
Encryption Algorithm in Python.py
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
import random
import string
#import constants of string module: punctuation, digits, ascii letters. And a space character
chars = " " + string.punctuation + string.digits + string.ascii_letters
#turn string into list
chars = list(chars)
key = chars.copy()
#shuffle key
random.shuffle(key)
#ENCRYPT
#text we will encrypt
plain_text = input("Enter message you want to encrypt: ")
#plain text encrypted
cipher_text = ""
#iterate over every character in plain_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}")
print("\n")
#DECRYPTION
cipher_text= input("Enter message you want to encrypt: ")
#cipher_text decrypted
plain_text = ""
#iterate over every letter in cipher_text
for letter in cipher_text:
index = key.index(letter)
plain_text += chars[index]
#enter decrypted text in the console. You should get the original message you typed in the console!
print(f"encrypted message: {cipher_text}")
print(f"original message: {plain_text}")
#list of characters
print(f"chars: {chars}")
#key list that is the chars variable shuffled
print(f"key: {key}")