字典攻击1.0
import itertools
import datetime
import hashlib
import time
def generatelibarry(library, length=8):
libararys = itertools.product(library,repeat=length)
dic = open(“paswordlirbarys.txt”,“w”,encoding=‘utf-8’)
for i in libararys:
dic.writelines(i)
dic.writelines("\n")
dic.close()
def dict_attack(path,password):
file = open(path)
for passwords in file:
print(passwords)
passwords = passwords.split("\n")[0]
if password == hashlib.md5(passwords.encode(encoding=“utf-8”)).hexdigest():
print(“你的密码是:{}”.format(passwords))
if name ==“main”:
word = “lalalalahhh”
starttime = datetime.datetime.now()
print(time.strftime("%Y%m%d%H%M%S",time.localtime(time.time())))
generatelibarry(word,length=6)
endtime = datetime.datetime.now()
print('The time cost: ')
print(endtime - starttime)