-
Notifications
You must be signed in to change notification settings - Fork 0
/
Firma.py
36 lines (28 loc) · 1.01 KB
/
Firma.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
import nacl.secret
import nacl.utils
Llave = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE)
Caja = nacl.secret.SecretBox(Llave)
Option = int(input(' 1 Cifrar\n 2 Comprobar\n 0 Parar \n~>:'))
while Option != 0:
if Option == 1:
Texto = open("F:\\Mensaje secreto secretioso.txt", "r")
Linea = Texto.readline()
while Linea:
Linea = Texto.readline()
mensaje = Linea.encode("utf-8")
mcifrado = Caja.encrypt(mensaje)
#MASCII = mcifrado.encode("ascii")
print('Firma:',mcifrado)
elif Option == 2:
assert len(mcifrado) == len(mensaje) + Caja.NONCE_SIZE + Caja.MACBYTES
mdescifrado = Caja.decrypt(mcifrado)
if(mdescifrado == mensaje):
print('Firma correspondiente')
else:
print('Firma erronea')
elif Option == 0:
print("Excelente")
break
else:
print('ERROR')
Option = int(input(' 1 Cifrar\n 2 Comprobar\n 0 Parar \n~>:'))