时间:2023-01-02 09:21:33 | 栏目:Python代码 | 点击:次
1、通过 string模块 自动生成字典;
2、使用permutations()函数,对字典进行全排列;
3、使用 md5模块 对全排列的字典进行转换;
4、使用了多线程,分别对5~18位字符串进行md5碰撞,以防止时间太长(虽然现在也要很久)。
def md5_poj(self, md5_value, k): if len(md5_value) != 32: print("error") return md5_value = md5_value.lower() # permutations() 全排列 for item in permutations(all_letters, k): item = "".join(item) if item == "hongrisec@2019": print(item) if md5(item.encode()).hexdigest() == md5_value: print('\n success: ' + md5_value + ' ==> ' + item) self.__mdfive = 1
其中 if len(md5_value) != 32 判断所输入的md5是否为32位的
def main(self): NT_md5 = input("请填写MD5:") start_time = time() t_list = [] print("正在查询...") # 添加线程 t_first = threading.Thread(target=self.md5_first, args=(NT_md5,)) t_first.daemon = 1 t_first.start() for k in range(5, 18): t = Process(target=self.md5_poj, args=(NT_md5, k)) # t = threading.Thread(target=self.md5_poj, args=(NT_md5, k)) t.daemon = 1 # 守护程序 t_list.append(t) # 启动所有线程 for i in t_list: i.start() # 当 __mdfive == 1 时结束所有线程 while 1: if self.__mdfive: break print("\n查询结束!") print('使用了 %f 秒'%(time() - start_time))
import threading from multiprocessing import Process from hashlib import md5 from itertools import permutations from string import ascii_letters, digits, ascii_lowercase, ascii_uppercase from time import time all_letters = ascii_lowercase + '.,;@' + digits class MDfive: def __init__(self): self.__mdfive = 0 def md5_poj(self, md5_value, k): if len(md5_value) != 32: print("error") return md5_value = md5_value.lower() # permutations() 全排列 for item in permutations(all_letters, k): item = "".join(item) if item == "hongrisec@2019": print(item) if md5(item.encode()).hexdigest() == md5_value: print('\n success: ' + md5_value + ' ==> ' + item) self.__mdfive = 1 # 判断 md5 是否与空匹配 def md5_first(self, md5_firstvalue): if len(md5_firstvalue) != 32: elif md5_firstvalue == "31d6cfe0d16ae931b73c59d7e0c089c0": print("\n密码为空!") self.__mdfive = 1 def main(self): NT_md5 = input("请输入MD5:") start_time = time() t_list = [] print("正在查询...") # 添加线程 t_first = threading.Thread(target=self.md5_first, args=(NT_md5,)) t_first.daemon = 1 t_first.start() for k in range(5, 18): t = Process(target=self.md5_poj, args=(NT_md5, k)) # t = threading.Thread(target=self.md5_poj, args=(NT_md5, k)) t.daemon = 1 # 守护程序 t_list.append(t) # 启动所有线程 for i in t_list: i.start() # 当 __mdfive == 1 时结束所有线程 while 1: if self.__mdfive: break print("\n查询结束!") print('使用了 %f 秒'%(time() - start_time)) if __name__ == '__main__': MDfive().main()