Задачка с хешами на питоне
Dan J
Given a colleague has written the code in hashcrack.py, a. Can you explain what it tries to achieve?
b. Can you fix it, so that it runs without throwing errors?
c. How would you improve it?
d. Bonus: Can you crack the provided hashes?
=> Please supply your answers as a text and your improved code
from hashlib import md5

import re user1 = 'User1 :B:19962313:cf5f1a283b7ea2a0d52d34f295970d89'
user2 = 'User2 :B:da60a9e4:abaa4c5894ec6d5ece7ce3e498c9c260'
user3 = 'User3 :B:5a69283e:4a29e4f4388e3fe37db970586a2e38a8'
words = ["123456", "password", "love"]
results = open('results.txt','w')
match = re.match(r"(.*)\t:B:(.*):(.*)", user1)
if match != None:
user = match.group(1)
hash1 = md5(words[1]).hexdigest()
salted = hash1 + '-' + match.group(2)
hash2 = md5(salted).hexdigest()
if hash == match.group3:
print "\nWe have a match: " + user1 + "'s password is weak!"
results.write(user1 + 'has the following password: ' + words[1])
results.close()
match = re.match(r"(.*)\t:B:(.*):(.*)", user2)
if match != None:
user = match.group(1)
hash1 = md5(words[2]).hexdigest()
salted = hash1 + '-' + match.group(2)
hash2 = md5(salted).hexdigest()
if hash == match.group3:
print "\nWe have a match: " + user2 + "'s password is weak!"
results.write(user2 + 'has the following password: ' + words[2])
results.close()
match = re.match(r"(.*)\t:B:(.*):(.*)", user3)
if match != None:
user = match.group(1)
hash1 = md5(words[3]).hexdigest()
salted = hash1 + '-' + match.group(2)
hash2 = md5(salted).hexdigest()
if hash == match.group3:
print "\nWe have a match: " + user3 + "'s password is weak!"
results.write(user3 + 'has the following password: ' + words[3])
results.close()
Dan J больше 2 лет назадСпасибо 0
0 чел.