2020-12-22學習記錄
阿新 • • 發佈:2020-12-23
技術標籤:python
Python學習記錄
今天課上跟老師學習一個叫做字典攻擊的程式,因為自己沒有學到位,聽得雲裡霧裡的,但還是跟著老師敲,準備以後自己慢慢學習。
# 字典攻擊 import itertools # 迭代器 import datetime import hashlib import time def generatelibary(library, length=8): libararys = itertools.product(library,repeat=length) dic = open("paswordlirbarys.txt","w",encoding='utf-8')#寫模式開啟檔案 for i in libararys: dic.writelines(i) dic.writelines("\n") dic.close() #x = hashlib.md5("123".encode(encoding="utf-8")).hexdigest()#hash演算法儲存密碼 #202cb962ac59075b964b07152d234b70 #print(x) def dict_attack(path,password): file = open(path) for passwords in file: #print(passwords) passwords = passwords.split("\n")[0] if password == hashlib.md5(passwords.encode(encoding="utf-8")).hexdigest(): print("你的密碼是:{}".format(passwords)) if __name__ == "__main__": #lowercase = 'abcdefghijklmnopqrstuvwxyz'#字元組合 #uppercase = 'ABCDEFGHIJKLMNOPQRS' #digits = '0123456789' word = "xiaowng2067" #special = """!"#$%&'( )*+,-./:;<=>
[email protected][]^_`{|}~""" #word = lowercase + uppercase + digits + special starttime = datetime.datetime.now() # 獲取當前時間 print(time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))) generatelibary(word,length=6) #生成8位數字字典 #dict_attack("paswordlirbarys.txt","05213bc82bacf7312806baf095038402") endtime = datetime.datetime.now() print(time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))) print('The time cost: ') print(endtime - starttime)#時間
C:\Users\86158\AppData\Local\Programs\Python\Python39\python.exe C:/Users/86158/PycharmProjects/class1/venv/練習4.py
20201222231642
20201222231644
The time cost:
0:00:01.796485
Process finished with exit code 0