-
# 字典攻击 -
import itertools # 迭代器
-
import datetime
-
import hashlib
-
import time
-
def generatelibary(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()
-
#x = hashlib.md5("123".encode(encoding="utf-8")).hexdigest()#hash算法存储密码
-
#202cb962ac59075b964b07152d234b70
-
#print(x)
-
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__":
-
#lowercase = 'abcdefghijklmnopqrstuvwxyz'#字符组合
-
#uppercase = 'ABCDEFGHIJKLMNOPQRS'
-
#digits = '0123456789'
-
word = "xiaowng2067"
-
#special = """!"#$%&'( )*+,-./:;<=>?@[]^_`{|}~"""
-
#word = lowercase + uppercase + digits + special
-
starttime = datetime.datetime.now() # 获取当前时间
-
print(time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())))
-
generatelibary(word,length=6) #生成8位数字字典
-
#dict_attack("paswordlirbarys.txt","05213bc82bacf7312806baf095038402")
-
endtime = datetime.datetime.now()
-
print(time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())))
-
print('The time cost: ')
-
print(endtime - starttime)#时间
六位密码测试效果最好,八位太长,需要时间过多
后记
近期有很多朋友通过私信咨询有关Python学习问题。为便于交流,点击蓝色自己加入讨论解答资源基地

被折叠的 条评论
为什么被折叠?



