为什么这段代码成功后会输出失败信息?

发布于 2024-11-03 07:57:25 字数 1040 浏览 0 评论 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对应于单词列表中提供的任何单词 消息,起初我以为这是一个身份问题,但现在我毫无头绪。

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反目相谮 2024-11-10 07:57:26

当然,它会打印“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

Surely it will print 'PRIVSG [..] Collision' and after 'PRIVSG [..] The hash given'.

What you have to do is:

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
绮烟 2024-11-10 07:57:26

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文