Python 为什么此代码在成功后输出失败消息?
代码通过对单词列表中的每一行进行散列,然后将其与指定的散列进行比较来运行Python 为什么此代码在成功后输出失败消息?,python,control-flow,Python,Control Flow,代码通过对单词列表中的每一行进行散列,然后将其与指定的散列进行比较来运行 我没有得到任何错误,但是当它找到一个散列时,它会打印出冲突message加上给定的哈希与wordlist消息中提供的任何单词都不对应,起初我认为这是一个识别问题,但现在我一无所知。如果不希望在检测到冲突后发送“哈希不对应”消息,则需要从函数返回(或以其他方式防止代码丢失)在发送“碰撞!”消息后。如果不希望在检测到碰撞后发送“哈希不对应”消息,则需要在“碰撞”后从函数返回(或以其他方式防止代码丢失)消息已发送。它肯定会打印“
我没有得到任何错误,但是当它找到一个散列时,它会打印出
冲突
message加上给定的哈希与wordlist
消息中提供的任何单词都不对应,起初我认为这是一个识别问题,但现在我一无所知。如果不希望在检测到冲突后发送“哈希不对应”消息,则需要从函数返回(或以其他方式防止代码丢失)在发送“碰撞!”消息后。如果不希望在检测到碰撞后发送“哈希不对应”消息,则需要在“碰撞”后从函数返回(或以其他方式防止代码丢失)消息已发送。它肯定会打印“PRIVSG[..]冲突”,并在“PRIVSG[..]给定的哈希”之后打印
你要做的是:
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')
当然,它会打印“PRIVSG[…]Collision”,并在“PRIVSG[…]给定的哈希”之后打印 你要做的是:
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=True缩进错误:意外缩进
error与nick=data行放在同一缩进中。拆分(“!”)[0]。替换(“:”,“”)我得到的是collision=True缩进错误:意外缩进
error与nick=data行放在同一缩进中。拆分(“!”)[0]。替换(“:”,“”)你能给我举个例子吗?@Pih的答案建议你做的就是“否则防止代码崩溃”。你明白这个问题吗?代码中目前没有任何机制阻止它在发现冲突后发送“不一致”消息。你能给我举个例子吗@Pih的答案建议您这样做:“否则,防止代码崩溃”。您明白问题所在吗?代码中目前没有机制阻止它在发现冲突后发送“不一致”消息。