import binascii, hashlib
import sys
def generate_ntlm_hash(text):
ntlm_hash = binascii.hexlify(hashlib.new('md4', text.encode('utf-16le')).digest())
return ntlm_hash
min_distance = float('inf')
closest_hash = ""
closest_word = ""
def read_hashes_from_file(filename):
hashes = []
with open(filename, 'r') as file:
for line in file:
line = line.strip()
if line:
hashes.append(line)
return hashes
def hamming_distance(hash1, hash2):
bin_hash1 = bin(int(hash1, 16))[2:].zfill(32)
bin_hash2 = bin(int(hash2, 16))[2:].zfill(32)
distance = sum(bit1 != bit2 for bit1, bit2 in zip(bin_hash1, bin_hash2))
return distance
def find_closest_hash(target_hash, hash_list, word):
global min_distance
global closest_hash
global closest_word
for hash_value in hash_list:
distance = hamming_distance(target_hash, hash_value)
if distance < min_distance:
min_distance = distance
closest_hash = hash_value
closest_word = word
return
def main():
dictionary_file = input("Enter the name of the dictionary file (e.g., michael.txt): ")
hash_file = input("Enter the name of the hashes file (e.g., hashes.txt): ")
try:
with open(dictionary_file, 'r') as file:
words = [word.strip() for word in file]
except FileNotFoundError:
print("Dictionary file not found.")
return
known_hashes = read_hashes_from_file(hash_file)
total_words = len(words)
current_word = 0
for word in words:
ntlm_hash = generate_ntlm_hash(word)
if ntlm_hash in known_hashes:
print(f"Word: {word}, NTLM Hash: {ntlm_hash}, Status: Cracked!")
else:
find_closest_hash(ntlm_hash, known_hashes,word)
completion_percentage = (current_word / total_words) * 100
sys.stdout.write(f"\rProcessing: {completion_percentage:.2f}% closest_word: {closest_word}, Min_distance: {min_distance:.2f}")
sys.stdout.flush()
current_word += 1
print(f"Word: {closest_word}, Closest Hash: {closest_hash}")
print("\nProcessing completed.")
if __name__ == "__main__":
main()
Now it does show the percentage of cracking and finds the closest Hamming distance of all the password texts that you have tried, and it also prints the closest word along with it.