密码学实验三:Hash算法之MD5加密
使用语言:python
说明:非用python写出了md5加密过程,使用python的函数库调用实现简单应用
import hashlib
def md5_encrypt(plaintext): # 参数plaintext为明文
h1 = hashlib.md5() # 创建md5对象
h1.update(plaintext.encode(encoding='utf-8')) # 必须声明encode
# 加密
encrypt_str = h1.hexdigest()
print("密文为:" + encrypt_str)
return encrypt_str
if __name__=='__main__':
print("---------------------Hash算法之md5加密---------------------")
plaintext = input("请输入明文:")
md5_encrypt(plaintext)
运行结果:
本代码仅供了解学习,可修改提升自己学习。