From 9ffbeb2e47f350497b59e8db865db0e025fc71ae Mon Sep 17 00:00:00 2001 From: "M. DUVAL" Date: Wed, 22 Mar 2017 21:47:45 +0100 Subject: [PATCH] Python version 3 --- testPass.py | 113 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 93 insertions(+), 20 deletions(-) diff --git a/testPass.py b/testPass.py index d90d545..6b46e04 100644 --- a/testPass.py +++ b/testPass.py @@ -1,34 +1,105 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import time +import sys +import locale + tempsN_1 = time.time(); globalTime = time.time() -nMot = 0 +nbMot = 0 +passwordCrypte = "" +tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ") +verbose = False def main(): - #passwordCrypte = "MatDuv1945" - passwordCrypte = "azerty" + gestionParams() tabPass =list("a") - print("test",2*2) + global passwordCrypte found, passTrouve = testPass(True,0,tabPass,passwordCrypte) if found == True : - print("Trouvé ! : " + passTrouve +" en " + str(time.time() - globalTime) + " secondes") + if(time.time() - globalTime) > 60 : + seconds = time.time() - globalTime + m, s = divmod(seconds, 60) + h, m = divmod(m, 60) + d ,h = divmod(h, 24) + if d != 0: + print("Found ! : " + passTrouve +" en " + "%d:%02d:%02d:%02d" % (d,h, m, s)) + elif h != 0 : + print("Found ! : " + passTrouve +" en " + "%d:%02d:%02d" % (h, m, s)) + else: + print("Found ! : " + passTrouve +" en " + "%d:%02d" % (m, s)) + else: + print("Found ! : " + passTrouve +" en " + str(time.time() - globalTime) + " secondes") + sys.exit() +def gestionParams(): + passSet = False + global passwordCrypte + global verbose + if len(sys.argv) > 1: + for argv in sys.argv: + if "--help" == argv or "-h" == argv: + helpMessage() + elif "--pass" in argv or "-p" in argv: + tabParam = "".join(str.split(argv,"=")[0]) + passwordCrypte = "".join(str.split(argv,tabParam + "=")) + for char in passwordCrypte: + if char not in tabChar: + print("Error : Unavaliable caractere \t" + char) + print() + helpMessage() + print("Searched password : \t"+ passwordCrypte) + passSet = True + elif "--verbose" == argv or "-v" == argv: + print("/!\ Verbose : Worst performance") + verbose = True + elif argv == sys.argv[0]: + print() + else: + print("Error : Unknown command \t" + argv) + print() + helpMessage() + else: + print("Error : You need to set a password to Search") + print() + helpMessage() + + if passSet == False: + print("Error : You need to set a password to Search") + print() + helpMessage() + +def helpMessage(): + print("Usage : " ) + print("\t--help, -h\t Print this message") + print("\t--pass=[passwordSearch], -p=[passwordSearch]") + print("\t\tSelect pasword to Search") + print("\t--verbose, -v\t More output") + print() + sys.exit() + +def testSpeed(tabPass): + global nbMot + global tempsN_1 + if (time.time() - tempsN_1) > 5 : + WordsSeconds = round(nbMot/(time.time() - tempsN_1)) + locale.setlocale(locale.LC_ALL, 'french_france') + WordsSeconds = locale.format('%d', WordsSeconds, grouping=True) + str_number = str(ord('a')) + print('{:>30}'.format(WordsSeconds) + " Mots/s \tMot actuel : " + "".join(tabPass)) + nbMot = 0 + tempsN_1 = time.time() -#tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") -tabChar = list("abcdefghijklmnopqrstuvwxyz") - - def testPass(isFirst, pos, tabPass, password ): found = False passTrouve = "" - global nMot - global tempsN_1 - + global nbMot + global tempsN_1 + global verbose + #Première boucle, permet de parcourir l'enssembles des caractères du tableau for char in tabChar: tabPass[pos] = char - nMot = nMot +1; - if (time.time() - tempsN_1) > 5 : - print("\t\t\t" + str(nMot/(time.time() - tempsN_1)) + "Mots/s \tMot actuel : " + "".join(tabPass)); - nMot = 0; - tempsN_1 = time.time() + if verbose == True: + nbMot = nbMot +1; + testSpeed(tabPass) + if "".join(tabPass) == password: found=True passTrouve = "".join(tabPass) @@ -36,7 +107,9 @@ def testPass(isFirst, pos, tabPass, password ): #else: #print("".join(tabPass) + "\t | " + str(len(tabPass))) - + # Seconde boucle, ne s'execute que si on est dans la première instance de la fonction, + # elle permet de rajouter les caractère au fur et à mesure + if isFirst == True and found == False: while found != True: tabPass = tabPass + list('a') @@ -46,7 +119,7 @@ def testPass(isFirst, pos, tabPass, password ): passTrouve = "".join(tabPass) return found, passTrouve - + # Troisième boucle, elle permet d'itéré el caractère précédent dans la chainde de caractère if pos > 0 and found == False: for char in tabChar : tabPass[pos] = char