前言
源代码仅供学习参考,如存在违法行为与本站无关,请自行承担后果和责任
支持16/32位
from hashlib import md5
from itertools import count
import linecache
from time import time
#MD5破解
def decrypt_md5(md5_value,passwd_txt,count,lens):
md5_value=md5_value.lower()
for k in range(1,count+1):
text = get_line(passwd_txt,k)
f = k / count * 100
print ("MD5:"+md5_value+" "+"明文:"+text+" "+str(k)+"/"+str(count)+" "+str(round(f,2))+"%")
if enmd5(lens,text)==md5_value:
bool = True
break
else:
bool = False
continue
if bool:
print('\nSuccess: ',md5_value,'=>',text)
else:
print('\n\nFailed')
print('用时:',str(round((time()-start)/1000,2))+'S')
#MD5生成
def enmd5(len,text):
if len == 32:
return md5(text.encode()).hexdigest()
elif len == 16:
return md5(text.encode()).hexdigest()[8:-8]
#读取行数
def line(passwd_txt):
with open(passwd_txt,'rb') as f:
count = 0
last_data = '\n'
while True:
data = f.read(0x400000)
if not data:
break
count += data.count(b'\n')
last_data = data
if last_data[-1:] != b'\n':
count += 1
return count
#读取指定行数据
def get_line(passwd_txt, nums_line):
return linecache.getline(passwd_txt, nums_line).strip()
def main():
md5_value = str(input("> 输入MD5\n"))
if len(md5_value)==16:
lens = 16
elif len(md5_value)==32:
lens = 32
else:
print('请输入16位或32位的MD5')
exit()
passwd_txt = str(input("> 密码字典\n"))
if passwd_txt == "":
print('密码字典不能为空')
exit()
count = line(passwd_txt)
decrypt_md5(md5_value,passwd_txt,count,lens)
if __name__ == '__main__':
start=time()
main()
评论一下?