-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescifradoVignere.py
29 lines (22 loc) · 1.05 KB
/
descifradoVignere.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
alphabet = 'ABCDEFGHIJKLMNÑOPQRSTUVWXYZ'
key = 'PEDRONAVAJA'
text = "GYLKWQRVEBTPXDJRQDDVQNPHHGQGUWRNPPWHRGCONLJOHMÑCOXEEAVASIÑDOEQPETAPVHEOPEKRXYAEVRUHAÑVNRSIVPZBSXINLEWSMGBSHEEITVDEENSVR"
def vigenere_descifrar(texto_plano, clave, modulo):
alfabeto = alphabet
n = len(alfabeto)
# Cifrado Vigenère
def get_index(c):
return alfabeto.index(c) if c in alfabeto else None
texto_plano_indices = [get_index(c) for c in texto_plano]
clave_indices = [get_index(c) for c in clave]
texto_cifrado_indices = []
for i, index in enumerate(texto_plano_indices):
if index is not None:
key_index = clave_indices[i % len(clave_indices)]
texto_cifrado_indices.append((index - key_index) % n)
else:
texto_cifrado_indices.append(index) # Mantener caracteres no soportados
texto_cifrado = ''.join(alfabeto[i] if i is not None else texto_plano[idx]
for idx, i in enumerate(texto_cifrado_indices))
return texto_cifrado
print(vigenere_descifrar(text, key,27))