# -*- coding: utf-8 -*- import time import sys import locale tempsN_1 = time.time(); globalTime = time.time() nbMot = 0 passwordCrypte = "" tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ") verbose = False def main(): gestionParams() tabPass =list("a") global passwordCrypte found, passTrouve = testPass(True,0,tabPass,passwordCrypte) if found == True : 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() def testPass(isFirst, pos, tabPass, password ): found = False passTrouve = "" 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 if verbose == True: nbMot = nbMot +1; testSpeed(tabPass) if "".join(tabPass) == password: found=True passTrouve = "".join(tabPass) return found, passTrouve #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') found,passTrouve =testPass(False,len(tabPass)-1 , tabPass,password) if found == True : found=True 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 found, passTrouve =testPass(False,pos-1, tabPass,password) if found == True : found=True passTrouve = "".join(tabPass) return found, passTrouve passTrouve = "".join(tabPass) return found , passTrouve if __name__ == '__main__' : main()