diff --git a/src/detecteur_crypto.py b/src/detecteur_crypto.py index 870d6a5..351ca71 100644 --- a/src/detecteur_crypto.py +++ b/src/detecteur_crypto.py @@ -3,6 +3,7 @@ import time from typing import List, Union from pathlib import Path +from rich.progress import Progress # Import des modules d'analyse from src.analyzers.aes_cbc_analyzer import Aes_Cbc_Analyzer from src.crypto_analyzer import CryptoAnalyzer @@ -358,6 +359,47 @@ def attaque_dictionnaire_manuelle(self, chemin_fichier: str, algorithme_choisi: print(f"Erreur lors de l'attaque: {str(e)}") temps_execution = time.time() - debut_attaque return ResultatAnalyse("", b"", 0.0, b"", temps_execution, 0) + + def attaque_dictionnaire(self,chemin_fichier_chiffrer: str, algo : str, chemin_dico : str = "keys/wordlist.txt"): + + with Progress() as progress: + analyzer = self.analyzers[algo] + + cle_candidates = analyzer.generer_cles_candidates(chemin_dico) + + with open(chemin_dico,'r') as d: + dico = d.readlines() + + with open(f"data/{chemin_fichier_chiffrer}",'rb') as f : + texte_chiffrer = f.read() + + task_id = progress.add_task("Testing...",total=len(cle_candidates)) + + current_task = 0 + + advance = 1 + + + while current_task < len(cle_candidates) : + time.sleep(0.5) + + essai_dechiffrage = analyzer.dechiffrer(f"data/{chemin_fichier_chiffrer}", cle_candidates[current_task]) + + if essai_dechiffrage != b"" : + + progress.update(task_id,advance=len(cle_candidates) - current_task) + + return essai_dechiffrage + + current_task+=1 + + progress.update(task_id,advance=advance) + + + return "Aucune clé trouvé" + + # print("\n Process is done ...") + -# print(DetecteurCryptoOrchestrateur().analyser_fichier_specifique(f"{os.path.abspath(os.curdir)}\\CryptoForensic-Python\\data\\mission2.enc")) +# print(DetecteurCryptoOrchestrateur().attaque_dictionnaire("mission1.enc","Fernet"))