-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypt.py
More file actions
26 lines (20 loc) · 780 Bytes
/
crypt.py
File metadata and controls
26 lines (20 loc) · 780 Bytes
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
from cryptography.fernet import Fernet
from tkinter.messagebox import askyesno
def generate_key():
if askyesno("Clé de chiffrement", "Voulez-vous générer une nouvelle clé?"):
return Fernet.generate_key()
else:
return input("Entrez votre clé ici: ")
def encrypt_message(message, key):
cipher_suite = Fernet(key)
ciphertext = cipher_suite.encrypt(message)
return ciphertext
def main():
# Génération automatique de la clé
key = generate_key()
print("Clé de chiffrement générée :", key)
plaintext = input("Entrez le message à chiffrer : ").encode('utf-8')
ciphertext = encrypt_message(plaintext, key)
print("Message chiffré :", ciphertext)
if __name__ == "__main__":
main()