已知一个999999以下的数的md5值,通过撞库的方式解密:
将999999以下的数的md5值存入md5.txt:
import hashlib
with open('md5.txt', 'w') as f:
print('正在写入。。。')
for i in range(0, 999999):
md5 = hashlib.md5(str(i).encode()).hexdigest() + '\n'
f.write(md5)
print('写入完成。')
撞库解密:
def md5decrypt(num: str):
with open('md5.txt', 'r') as f:
result = 0
for line in f:
line = line.split('\n')
if num == line[0]:
print('解密成功,密文为:', result)
return result
else:
result += 1
print('解密失败!')
return None
if __name__ == '__main__':
r = md5decrypt('d3e4029427aa766ffa42fd454b28d3b4')
if r:
print('解密成功:', r)
else:
print('解密失败!')