-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17_Cryptography.py
146 lines (126 loc) · 2.74 KB
/
17_Cryptography.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
""" Diccionarios """
KEYS = {
'a': 'w',
'b': 'E',
'c': 'x',
'd': '1',
'e': 'a',
'f': 't',
'g': '0',
'h': 'C',
'i': 'b',
'j': '!',
'k': 'z',
'l': '8',
'm': 'M',
'n': 'I',
'o': 'd',
'p': '.',
'q': 'U',
'r': 'Y',
's': 'i',
't': '3',
'u': ',',
'v': 'J',
'w': 'N',
'x': 'f',
'y': 'm',
'z': 'W',
'A': 'G',
'B': 'S',
'C': 'j',
'D': 'n',
'E': 's',
'F': 'Q',
'G': 'o',
'H': 'e',
'I': 'u',
'J': 'g',
'K': '2',
'L': '9',
'M': 'A',
'N': '5',
'O': '4',
'P': '?',
'Q': 'c',
'R': 'r',
'S': 'O',
'T': 'P',
'U': 'h',
'V': '6',
'W': 'q',
'X': 'H',
'Y': 'R',
'Z': 'l',
'0': 'k',
'1': '7',
'2': 'X',
'3': 'L',
'4': 'p',
'5': 'v',
'6': 'T',
'7': 'V',
'8': 'y',
'9': 'K',
'.': 'Z',
',': 'D',
'?': 'F',
'!': 'B',
' ': '&',
}
def cipher_v2(message):
cipher_message = ''
for letter in message:
cipher_message += KEYS[letter]
return cipher_message
def decipher_v2(message):
decipher_message = ''
for letter in message:
for key, value in KEYS.items():
if value == letter:
decipher_message += key
return decipher_message
def cipher_v1(message):
words = message.split(' ')
cipher_message = []
for word in words:
cipher_word = ''
for letter in word:
cipher_word += KEYS[letter]
cipher_message.append(cipher_word)
return ' '.join(cipher_message)
def decipher_v1(message):
words = message.split(' ')
decipher_message = []
for word in words:
decipher_word = ''
for letter in word:
for key, value in KEYS.items():
if value == letter:
decipher_word += key
decipher_message.append(decipher_word)
return ' '.join(decipher_message)
def run():
command = None
while command != 's':
command = str(input('''--- * --- * --- * --- * --- * --- * --- * ---
Bienvenido a criptografía. ¿Qué deseas hacer?
[c]ifrar mensaje
[d]ecifrar mensaje
[s]alir
'''))
if command == 'c':
message = str(input('Escribe tu mensaje: '))
cipher_message = cipher_v2(message)
print(cipher_message)
elif command == 'd':
message = str(input('Escribe tu mensaje cifrado: '))
decipher_message = decipher_v2(message)
print(decipher_message)
elif command == 's':
pass
else:
print('¡Comando no encontrado!')
if __name__ == '__main__':
print('M E N S A J E S C I F R A D O S')
run()