-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.py
42 lines (33 loc) · 1.11 KB
/
decrypt.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
import string
# stores all upper case alphabets
all_alphabets = list(string.ascii_uppercase)
keyword = input("Enter Keyword: ")
keyword = keyword.upper()
ciphertext = input("Input Text to Decrypt (remove special characters first!): ")
# converts message to list
ct = []
for i in ciphertext:
ct.append(i.upper())
# removes default elements
def remove_duplicates(list):
key = []
for i in list:
if i not in key:
key.append(i)
return key
keyword = remove_duplicates(keyword)
# Stores the encryption list
encrypting = remove_duplicates(keyword + all_alphabets)
# removes spaces and special characters from the encryption list
encrypting = [i for i in encrypting if i != ' ']
#encrypting = [i for i in encrypting if i.isalnum()]
# maps each element of the message to the encryption list and stores it in plaintext
plaintext = ""
for i in range(len(ct)):
if ct[i] != ' ':
plaintext = plaintext + all_alphabets[encrypting.index(ct[i])]
else:
plaintext = plaintext + ' '
print("Keyword:", keyword)
print("Ciphered Text:", ciphertext)
print("Message after Deciphering:", plaintext)