-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcripto1.py
More file actions
53 lines (46 loc) · 1.33 KB
/
Copy pathcripto1.py
File metadata and controls
53 lines (46 loc) · 1.33 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
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 26 15:59:43 2016
"""
#son algunas de las funciones utilizadas en cripto_hist.py con ligeros cambios para facilitar
#su uso en los programas client.py y server.py
#convierte el texto en mayusculas
def normalizar(texto):
tn = ""
for letra in texto:
indx = ord(letra)
if 97 <= indx <= 122:
indx = indx - 32
tn = tn + chr(indx)
elif 65 <= indx <= 90:
tn = tn + letra
return tn
# 28-oct
#cifrado Vigenere
def vigenere(text,cifrador):
tn = normalizar(text)
cifrador = normalizar(cifrador)
while len(cifrador) < len(tn):
cifrador += cifrador
tv=""
for i in range(len(tn)):
index = ord(tn[i]) + ord(cifrador[i])-65
while index > 90:
index = index - 26
tv += chr(index)
return tv
#descifrado Vigenere
def decr_vigenere(text,descifrador):
tn = normalizar(text)
descifrador = normalizar(descifrador)
while len(descifrador) < len(tn):
descifrador += descifrador
tdv =""
for i in range(len(tn)):
for j in range(len(descifrador)):
if i == j:
index = ord(tn[i]) - ord(descifrador[j]) + 65
while index < 65:
index = index + 26
tdv += chr(index)
return tdv