diff options
| author | jerome <jerome@xlinfo.fr> | 2025-10-12 17:41:43 +0200 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2025-10-12 17:41:43 +0200 |
| commit | ec8893a097a6c0fffebd7db9e4a5568a3bf4df47 (patch) | |
| tree | ffebe60c3aa98df05d14aec8cea937430272c1ec /crypto | |
| parent | ba41fa46e69dbb264dfbed1b9fca5daab44a07c7 (diff) | |
| download | python-ec8893a097a6c0fffebd7db9e4a5568a3bf4df47.tar.gz python-ec8893a097a6c0fffebd7db9e4a5568a3bf4df47.zip | |
organisation
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/cesar.py | 50 | ||||
| -rw-r--r-- | crypto/crack_hash.py | 33 | ||||
| -rw-r--r-- | crypto/crack_md5.py | 24 | ||||
| -rw-r--r-- | crypto/rot13.py | 16 |
4 files changed, 123 insertions, 0 deletions
diff --git a/crypto/cesar.py b/crypto/cesar.py new file mode 100644 index 0000000..cc58d8f --- /dev/null +++ b/crypto/cesar.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +import string + + +def decalage(char, key): + liste = list(string.ascii_lowercase)*2 + list(string.ascii_uppercase)*2 + #print(liste) + if char not in liste: + return char + else: + return liste[liste.index(char)+key] + +# print(decalage("a",3)) + + +print("********************") +print("Chiffrement de César") +print("********************") + +menu = ["c) Chiffrer un message", "d) Dechiffrer un message", "q) Quitter"] + +while True: + for choix in menu: + print(choix) + rep = input("Votre choix : ") + match rep.lower(): + case "c": + msgChiffre = str() + msg = input("Votre message : ") + clef = int(input("Entrez votre clef (entre 1 et 25) : ")) + for lettre in msg: + #msgChiffre = msgChiffre + decalage(lettre,clef) + msgChiffre += decalage(lettre, clef) + print("\nVotre message chiffré : ", msgChiffre, "\n") + print("********************") + msg = "" + msgChiffre = "" + case "d": + msg = str() + msgChiffre = input("Votre message : ") + for clef in range(25,0,-1): + for lettre in msgChiffre: + msg += decalage(lettre, clef) + print(f"rot{26-clef} : {msg}") + msg = "" + print("********************") + case "q": + print("bye") + exit() diff --git a/crypto/crack_hash.py b/crypto/crack_hash.py new file mode 100644 index 0000000..b51cec7 --- /dev/null +++ b/crypto/crack_hash.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +"""crack_hash module""" +import sys +import hashlib +import argparse + + + +def crack_hash(hashlist, wordlist, hashsum): + """ + Args: + hashlist la liste de hashes à trouver + wordlist: le dictionnaire + hashsum: la somme de controle : md5,sha256 ou sha512 + """ + with open(hashlist,"r") as fichier1: + hashes=fichier1.readlines() + for hash in hashes: + with open(wordlist, "r") as fichier2: + lignes = fichier2.readlines() + for ligne in lignes: + if getattr(hashlib,hashsum)(ligne.strip().encode()).hexdigest() == hash.strip(): + print(f"trouvé: {ligne.strip()}") + break + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('hashlist', help='La liste de hash à trouver') + parser.add_argument('wordlist', help='Le dictionnaire choisi') + parser.add_argument('hashsum', help='la somme de contrôle : md5,sha256 ou sha512') + parser.parse_args() + crack_hash(sys.argv[1], sys.argv[2], sys.argv[3]) + diff --git a/crypto/crack_md5.py b/crypto/crack_md5.py new file mode 100644 index 0000000..00bac2b --- /dev/null +++ b/crypto/crack_md5.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +"""crack_md5 module""" +import sys +import hashlib + +def crack_md5(hash, wordlist): + """ + Args: + hash : le hash à trouver + wordlist: le dictionnaire + """ + with open(wordlist, "r") as fichier: + lignes = fichier.readlines() + for ligne in lignes: + if hashlib.md5(ligne.strip().encode()).hexdigest() == hash.strip(): + print(f"trouvé: {ligne.strip()}") + break + +if __name__ == "__main__": + try: + crack_md5(sys.argv[1], sys.argv[2]) + except IndexError: + print(f"{sys.argv[0]} demande des arguments. Voir l'aide.") + diff --git a/crypto/rot13.py b/crypto/rot13.py new file mode 100644 index 0000000..b2730f1 --- /dev/null +++ b/crypto/rot13.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import string + +def rot13(char): + liste = list(string.ascii_lowercase)*2 + list(string.ascii_uppercase)*2 + if char not in liste: + return char + else: + return liste[liste.index(char)+13] + +msg = input("Votre message : ") +msgChiffre = str() +for lettre in msg: + msgChiffre = msgChiffre + rot13(lettre) +print(msgChiffre) |
