Python version 3

PythonBranch
Matthieu DUVAL 8 years ago
parent bca161e5ec
commit 9ffbeb2e47

@ -1,34 +1,105 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
import sys
import locale
tempsN_1 = time.time(); tempsN_1 = time.time();
globalTime = time.time() globalTime = time.time()
nMot = 0 nbMot = 0
passwordCrypte = ""
tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ")
verbose = False
def main(): def main():
#passwordCrypte = "MatDuv1945" gestionParams()
passwordCrypte = "azerty"
tabPass =list("a") tabPass =list("a")
print("test",2*2) global passwordCrypte
found, passTrouve = testPass(True,0,tabPass,passwordCrypte) found, passTrouve = testPass(True,0,tabPass,passwordCrypte)
if found == True : 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()
#tabChar = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") def helpMessage():
tabChar = list("abcdefghijklmnopqrstuvwxyz") 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 ): def testPass(isFirst, pos, tabPass, password ):
found = False found = False
passTrouve = "" passTrouve = ""
global nMot global nbMot
global tempsN_1 global tempsN_1
global verbose
#Première boucle, permet de parcourir l'enssembles des caractères du tableau
for char in tabChar: for char in tabChar:
tabPass[pos] = char tabPass[pos] = char
nMot = nMot +1; if verbose == True:
if (time.time() - tempsN_1) > 5 : nbMot = nbMot +1;
print("\t\t\t" + str(nMot/(time.time() - tempsN_1)) + "Mots/s \tMot actuel : " + "".join(tabPass)); testSpeed(tabPass)
nMot = 0;
tempsN_1 = time.time()
if "".join(tabPass) == password: if "".join(tabPass) == password:
found=True found=True
passTrouve = "".join(tabPass) passTrouve = "".join(tabPass)
@ -36,6 +107,8 @@ def testPass(isFirst, pos, tabPass, password ):
#else: #else:
#print("".join(tabPass) + "\t | " + str(len(tabPass))) #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: if isFirst == True and found == False:
while found != True: while found != True:
@ -46,7 +119,7 @@ def testPass(isFirst, pos, tabPass, password ):
passTrouve = "".join(tabPass) passTrouve = "".join(tabPass)
return found, passTrouve 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: if pos > 0 and found == False:
for char in tabChar : for char in tabChar :
tabPass[pos] = char tabPass[pos] = char

Loading…
Cancel
Save