-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.py
41 lines (32 loc) · 958 Bytes
/
encrypt.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
import string
# stores all upper case alphabets
all_alphabets = list(string.ascii_uppercase)
keyword = input("Enter Keyword: ")
keyword = keyword.upper()
plaintext = input("Input Text to Encrypt: ")
# converts message to list
pt = []
for i in plaintext:
pt.append(i.upper())
# removes duplicate elements
def duplicates(list):
key = []
for i in list:
if i not in key:
key.append(i)
return key
keyword = duplicates(keyword)
# Stores the encryption list
encrypting = duplicates(keyword + all_alphabets)
# removes spaces from the encryption list
encrypting = [i for i in encrypting if i != ' ']
# maps each element of the message to the encryption list and stores it in ciphertext
ciphertext = ""
for char in pt:
if char != ' ':
ciphertext += encrypting[all_alphabets.index(char)]
else:
ciphertext += ' '
print("Keyword:", keyword)
print("Message before Ciphering:", plaintext)
print("Ciphered Text:", ciphertext)