python monoalphabetic substitution cipher

Solutions on MaxInterview for python monoalphabetic substitution cipher by the best coders in the world

showing results for - "python monoalphabetic substitution cipher"
Michel
18 Oct 2019
1key_dict = {
2    'a': 'm',
3    'b': 'n',
4    'c': 'b',
5    'd': 'v',
6    'e': 'c',
7    'f': 'x',
8    'g': 'z',
9    'h': 'a',
10    'i': 's',
11    'j': 'd',
12    'k': 'f',
13    'l': 'g',
14    'm': 'h',
15    'n': 'j',
16    'o': 'k',
17    'p': 'l',
18    'q': 'p',
19    'r': 'o',
20    's': 'i',
21    't': 'u',
22    'u': 'y',
23    'v': 't',
24    'w': 'r',
25    'x': 'e',
26    'y': 'w',
27    'z': 'q',
28    ' ': ' ',
29}
30
31def get_key(value):
32    for key, val in key_dict.items():
33        if (val == value):
34            return key
35
36def monoalphabetic_encrypt():
37    word = input("Enter the plain text: ")
38    c = ''
39    for i in word:
40        i = key_dict[i]
41        c += i
42    return c
43
44def monoalphabetic_decrypt():
45    word = input("Enter the cipher text: ")
46    c = ''
47    for i in word:
48        i = get_key(i)
49        c += i
50    return c