0
  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 correspond to any supplied word in the wordlist消息,起初我虽然这是一个身份问题,但现在我一无所知。

4

2 回答 2

2

它肯定会打印“PRIVSG [..] Collision”并在“PRIVSG [..] The hash given”之后打印。

你要做的是:

collision = False
[..] 
if word_hash==hash_file:
                      sck.send('PRIVMSG ' + chan + " :" 'Collision!  The word corresponding to the given hash is ' + line + '\r\n')
                      collision = True

if not collision
     sck.send('PRIVMSG ' + chan + " :" 'The hash given does not correspond to any
于 2011-04-26T17:19:41.637 回答
1

如果您不希望在检测到碰撞后发送“哈希不对应”消息,则需要在“碰撞!”之后从函数返回(或以其他方式防止代码失败)。消息被发送。

于 2011-04-26T17:19:31.427 回答