小鱼要学数据结构与算法(基于python)—Day15散列、散列函数、区块链

散列

在这里插入图片描述

一、知识概览

本章主要讲解散列、散列函数、区块链,知识概览如下。

1.1 散列

散列

1.2 散列函数

散列函数

1.3 散列函数应用

重点介绍区块链
散列函数应用

二、python散列函数库

import hashlib
u1=hashlib.md5("hello world!".encode("utf-8")).hexdigest()
u2=hashlib.sha1("hello world!".encode("utf-8")).hexdigest()
print(u1)
print(u2)

输出

fc3ff98e8c6a0d3087d515c0473f8677
430ce34d020724ed75a196dfc2ad67c77772d169

如果报错

Unicode-objects must be encoded before hashing

hash前必须把数据转换成bytes类型,注意.encode(“utf-8”)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章