-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonoalphabetic_cipher.py
More file actions
54 lines (35 loc) · 1.46 KB
/
Monoalphabetic_cipher.py
File metadata and controls
54 lines (35 loc) · 1.46 KB
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
52
53
54
#Encrypting Method
def Encrypt_text(keyword_pattern,plain_t):
cipher_t = list()
for char in plain_t:
if char in keyword_pattern:
cipher_t.append(keyword_pattern[char])
else:
print("pattern cannot be encrypted as no vlaue for the character:{}".format(char))
print("The cipher text for plain text",plain_t,"is {}".format("".join(cipher_t)))
return cipher_t
#Decrypting Method
def Decrypt_text(keyword_pattern,cipher_t):
plain_t=list()
for char in cipher_t:
for kei in keyword_pattern.keys():
if keyword_pattern[kei] == char:
plain_t.append(kei)
print("The plain text for ciphre text {}".format("".join(cipher_t)),"is {}".format("".join(plain_t)))
return None
#Main Method
def main():
number = int(input("Enter the number for the inputs:"))
keyword_pattern = dict()
for i in range(number):
kei = input("input the key character :")
vlues = input("input the value for the corresponding key :")
keyword_pattern[kei] = vlues
#for kei,vlue in keyword_pattern.items():
#print(kei, vlue)
plain_t = input("Enter plain text")
cipher_t = Encrypt_text(keyword_pattern, plain_t)
Decrypt_text(keyword_pattern,cipher_t)
#Calling Main_Method
if __name__ == "__main__":
main()