Python正課61 hashlib模組

2022-01-30 04:06:15 字數 2196 閱讀 8896

123456asd ==> hash字串

123456asd ==> md5 ==> hash字串

客戶端 ====> hash字串 ====> 服務端

hash字串

import hashlib

m = hashlib.md5()

m.update('hello'.encode('utf-8'))

m.update('world'.encode('utf-8'))

res = m.hexdigest() # helloworld

print(res)

# fc5e038d38a57032085441e7fe7010b0

m1 = hashlib.md5()

m1.update('he'.encode('utf-8'))

m1.update('llo'.encode('utf-8'))

m1.update('wor'.encode('utf-8'))

m1.update('ld'.encode('utf-8'))

res = m1.hexdigest() # helloworld

print(res)

# fc5e038d38a57032085441e7fe7010b0

m = hashlib.md5()

# 加內容方式1

m.update('檔案所有的內容')

m.hexdigest()

# 加內容方式2(推薦)

m.update('hello'.encode('utf-8'))

m.update('world'.encode('utf-8'))

res = m.hexdigest() # helloworld

print(res)

m.update('檔案所有的內容')

m.hexdigest()

f = open('a.txt', mode='rb')

f.seek()

f.read(2000)

import hashlib

cryptograph='aee949757a2e698417463d47acac93df'

passwds=[

'alex3714',

'alex1313',

'alex94139413',

'alex123456',

'123456alex',

'a123lex',

]# 製作密碼字典

dic = {}

for p in passwds:

res = hashlib.md5(p.encode('utf-8'))

dic[p] = res.hexdigest()

# 模擬撞庫得到密碼

for k,v in dic.items():

if v == cryptograph:

print('撞庫成功!明文密碼是:%s' %k)

break

import hashlib

passwds=[

'alex3714',

'alex1313',

'alex94139413',

'alex123456',

'123456alex',

'a123lex',

]def make_passwd_dic(passwds):

dic={}

for passwd in passwds:

m=hashlib.md5()

m.update(passwd.encode('utf-8'))

dic[passwd]=m.hexdigest()

return dic

def break_code(cryptograph,passwd_dic):

for k,v in passwd_dic.items():

if v == cryptograph:

print('密碼是===>\033[46m%s\033[0m' %k)

cryptograph='aee949757a2e698417463d47acac93df'

break_code(cryptograph,make_passwd_dic(passwds))

Python正課4 變數

變數就是可以變化的量,量指的是事物的狀態,比如人的年齡 性別,遊戲角色的等級 金錢等等 為了讓計算機能夠像人一樣去記憶事物的某種狀態,並且狀態是可以發生變化的 詳細地說 程式執行的本質就是一系列狀態的變化,變是程式執行的直接體現 所以我們需要有一種機制能夠反映或者說是儲存下來 name egon 定...

python學習筆記5 加密模組hashlib

import hashlib md5 ybm pwd yuanbapqingsdfs234ff234hf f m hashlib.md5 bytes ybq ybm pwd.encode 把字串轉成bytes型別 m.update bytes ybq 加密,不能字串,只能傳bytes型別,二進位制 ...

Python正課39 迭代器

l egon liu alex i 0while i len l print l i i 1s1 s1.iter l l.iter t 1,t.iter d d.iter set1 set1.iter with open a.txt mode w as f f.iter passd d iterat...