解码 MD5 哈希 Python

问题描述 投票:0回答:0

我在 Python 上写了一个代码,来解码 MD5 哈希:

import time
import itertools, string
import hashlib
import sys
import signal
import threading

done = False
def signal_handler(signal, frame):
    print('You pressed Ctrl+C!')
    global done
    done=True
    sys.exit(0)        
    

def _attack(chrs, inputt):
    print("[+] Start Time: ", time.strftime('%H:%M:%S'))
    start_time = time.time()
    total_pass_try=0
    for n in range(1, 31+1):
      characterstart_time = time.time()
      
      for xs in itertools.product(chrs, repeat=n):
          saved = ''.join(xs)

          stringg = saved
          m = hashlib.md5()
          m.update(bytes(saved, encoding='utf-8'))
          total_pass_try +=1
          sys.stdout.write('\rPasswords tried: ' + str(total_pass_try))
          sys.stdout.flush()
          if m.hexdigest() == inputt:
              global done
              done = True

              print("\r\r _ _ _ _ _ _ _ _ _ _\n\n", stringg+'\n _ _ _ _ _ _ _ _ _ _')
              print("\n[-] End Time: ", time.strftime('%H:%M:%S'),"(%s sec)" % round((time.time() - start_time),1))
              print("\n[-] Total Keyword attempted: ", total_pass_try)
              f = open("response.txt", "w+")
              f.write(stringg)
              f.close()
              sys.exit("\nThank You !\n")
        
      print("\r[!]",n,"-character finished in %s sec\r" % round((time.time() - characterstart_time),1))

def main():
    inp_usr = input("Paste MD5 here:\n")
    chrs = string.printable.replace(' \t\n\r\x0b\x0c', '')
    chrs=r"""0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=[]{}|;':",./<>?~"""
    print('\nCharacter list:\n'+chrs+'\n')
    signal.signal(signal.SIGINT, signal_handler)
    return _attack( chrs,inp_usr.lower())

if __name__ == "__main__":
    main()

但是,在 MacBook Air 13 (M1)、8GB 内存和 CPU 上,我得到大约 170'000 哈希/秒。我需要更多,喜欢更多,请优化它,让它尽可能快地运行。

python python-3.x hash decode md5
© www.soinside.com 2019 - 2024. All rights reserved.