为什么这段代码成功后会输出失败信息?
if data.find('!mdcrack') != -1:
nick = data.split('!')[ 0 ].replace(':','')
m = hashlib.md5()
hash = ""
hash_file = str(arg[4])
wordlist = arg[5]
try:
wordlistfile = open(wordlist,"r")
except IOError:
sck.send('PRIVMSG ' + chan + " :" 'invalid file' + '\r\n')
else:
pass
for line in wordlistfile:
m = hashlib.md5()
line = line.replace("\n","")
m.update(line)
word_hash = m.hexdigest()
if word_hash==hash_file:
sck.send('PRIVMSG ' + chan + " :" 'Collision! The word corresponding to the given hash is ' + line + '\r\n')
sck.send('PRIVMSG ' + chan + " :" 'The hash given does not correspond to any supplied word in the wordlist' + '\r\n')
该代码的功能是对单词列表中的每一行进行哈希处理,然后将其与指定的哈希值进行比较。
我没有收到任何错误,但是当它找到哈希时,它会打印出 Collision!
消息以及 The hash given does not对应于单词列表中提供的任何单词
消息,起初我以为这是一个身份问题,但现在我毫无头绪。
if data.find('!mdcrack') != -1:
nick = data.split('!')[ 0 ].replace(':','')
m = hashlib.md5()
hash = ""
hash_file = str(arg[4])
wordlist = arg[5]
try:
wordlistfile = open(wordlist,"r")
except IOError:
sck.send('PRIVMSG ' + chan + " :" 'invalid file' + '\r\n')
else:
pass
for line in wordlistfile:
m = hashlib.md5()
line = line.replace("\n","")
m.update(line)
word_hash = m.hexdigest()
if word_hash==hash_file:
sck.send('PRIVMSG ' + chan + " :" 'Collision! The word corresponding to the given hash is ' + line + '\r\n')
sck.send('PRIVMSG ' + chan + " :" 'The hash given does not correspond to any supplied word in the wordlist' + '\r\n')
The code functions by hashing each line from the wordlist, and then comparing it to the hash specified.
I dont get any errors, but when it finds a hash it prints out the Collision!
message plus the The hash given does not correspond to any supplied word in the wordlist
message, at first I though it was an ident problem, but now I'm clueless.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,它会打印“PRIVSG [..] Collision”,并在“PRIVSG [..] The hash given”之后打印。
你需要做的是:
Surely it will print 'PRIVSG [..] Collision' and after 'PRIVSG [..] The hash given'.
What you have to do is:
如果您不希望在检测到碰撞后发送“哈希不对应”消息,则需要在“碰撞!”之后从函数返回(或以其他方式防止代码失败)。消息已发送。
If you don't want the "hash does not correspond" message to be sent after a collision is detected, you'll need to return from the function (or otherwise prevent the code from falling through) after the "Collision!" message is sent.