-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpilado.py
More file actions
53 lines (38 loc) · 1.09 KB
/
Copy pathpilado.py
File metadata and controls
53 lines (38 loc) · 1.09 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
import string
# Cuadro de Polibio modificado
square = [
['A','B','C','D','E'],
['F','G','H','I','J'],
['K','L','M','N','O'],
['P','Q','R','S','T'],
['U','V','W','X','Y']
]
# Crear diccionarios
encrypt_dict = {}
decrypt_dict = {}
for i in range(5):
for j in range(5):
encrypt_dict[square[i][j]] = f"{i+1}{j+1}"
decrypt_dict[f"{i+1}{j+1}"] = square[i][j]
# -------------------
# DESCIFRAR
# -------------------
mensaje = "15 32 45 24 15 33 41 35 34 35 15 44 41 15 43 11 11 34 11 14 24 15"
descifrado = ""
for num in mensaje.split():
descifrado += decrypt_dict.get(num, "?")
print("Mensaje descifrado:")
print(descifrado)
# -------------------
# CIFRAR
# -------------------
texto = """Si la felicidad tuviera una forma, tendría forma de cristal,
porque puede estar a tu alrededor sin que la notes.
Pero si cambias de perspectiva, puede reflejar una luz capaz de iluminarlo todo."""
texto = texto.upper()
cifrado = []
for letra in texto:
if letra in encrypt_dict:
cifrado.append(encrypt_dict[letra])
print("\nTexto cifrado:")
print(" ".join(cifrado))