-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecrypt
More file actions
22 lines (17 loc) · 705 Bytes
/
Decrypt
File metadata and controls
22 lines (17 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### Desciframos con GPG ####
import gnupg
from google.colab import files
# Inicializa el objeto GPG
gpg = gnupg.GPG()
# Pide al usuario el archivo cifrado a descifrar
file = files.upload()
filename = list(file.keys())[0]
# Pide al usuario la contraseña para descifrar
password = input("Introduzca la contraseña para descifrar: ")
# Descifra el archivo con GPG
with open(filename, 'rb') as f:
decrypted_data = gpg.decrypt(f.read(), passphrase=password)
with open(filename[:-4], "wb") as outfile: # El nombre original del archivo se obtiene eliminando los últimos 4 caracteres (.gpg)
outfile.write(decrypted_data.data)
# Descarga el archivo descifrado
files.download(filename[:-4])