python实现HMAC算法与应用[通俗易懂]
2023-06-13 09:15:14 时间
大家好,又见面了,我是你们的朋友全栈君。
Program : HMAC
In this program, you are required to invoke the scrypt
algorithms that are implemented in hashlib
build-in library. Your program does the following:
- Read the plaintext password as a text string
- Encode the password into byte array, with
utf-8
encoding - Read the salt byte array as a hex string
- Invoke the
scrypt
method with parameters n = 4 n=4 n=4, r = 8 r=8 r=8, p = 16 p=16 p=16 - Output the result byte array as a hex string
Example Input
Thi$ i$ my passw0rd!
477d15cb740ca1da08f6d851361b3c80
Example Output
fd5963b9e6905d36ca8d00e3a740a3ab7a40b3d60237b6f2ed3025eee770f2d71bc95ba3e98265bea4308250d02f0e10bb78e710d9f0ef7ae9a4fa52a0818d27
solution code
import hashlib
import base64
# define the function decode_utf8
def decode_utf8(in_bytes: bytes) -> str:
return in_bytes.decode('utf-8')
#
Read the plaintext password as a text string
password_str: str = input("input the plaintext password:")
# Encode the password into byte array, with utf-8 encoding
password_bytes: bytes = password_str.encode("utf-8")
# Read the salt byte array as a hex string
salt_str: str = input("input the salt:")
salt_bytes: bytes = bytes.fromhex(salt_str)
# Invoke the scrypt method with parameters n = 4 ,r = 8 ,p = 16
n: int = 4
r: int = 8
p: int = 16
result_bytes: bytes = hashlib.scrypt(password_bytes, salt=salt_bytes, n=n, r=r, p=p)
# Output the result byte array as a hex string
result_str: str = result_bytes.hex()
print(result_str)
output
input the plaintext password:Thi$ i$ my passw0rd!
input the salt:477d15cb740ca1da08f6d851361b3c80
fd5963b9e6905d36ca8d00e3a740a3ab7a40b3d60237b6f2ed3025eee770f2d71bc95ba3e98265bea4308250d02f0e10bb78e710d9f0ef7ae9a4fa52a0818d27
进程已结束,退出代码为 0
A screenshot of the console output of the program
受于文本篇幅原因,本文相关算法实现工程例如环境及相关库,无法展示出来,现已将资源上传,可自行点击下方链接下载。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/215911.html原文链接:https://javaforall.cn
相关文章
- pycharm python interpreter_python interpreter什么意思
- python实现矩阵的转置_Python实现矩阵转置的方法分析
- Python 实现大整数乘法算法
- python海龟作图红绿灯_海龟作图—用Python绘图
- python chr()和ord()_Python函数ord
- python pkl文件_Python字符串格式化输出的方式包括
- python修改第三方库重写_对Python第三方库,再次封装
- python程序化交易实例-用 Python 实现你的量化交易策略「建议收藏」
- 2022年10个用于时间序列分析的Python库推荐
- python递归函数讲解_Python递归函数实例讲解
- Python酒店评论文本数据分析:tf-idf、贝叶斯、逻辑回归,支持向量机SVM、K最邻近算法KNN、随机森林、LDA主题模型
- Python网络编程-网络编程中的异常处理(二)
- python-Python与SQLite数据库-处理SQLite查询结果(一)
- python-Python与PostgreSQL数据库-PostgreSQL数据库的基本知识(一)
- Python 简单沙盒绕过
- 在Linux上搭建Python开发环境(linux搭建python环境)
- Linux环境下安装Python(linux装python)
- 安装Python MySQL驱动之快速指南(python安装mysql驱动)
- 简易Python Selenium爬虫实现歌曲免费下载
- 下的应用玩转Python:Linux下的Python应用之旅(python在linux)
- Python在MSSQL中的应用实践(python与mssql)
- Linux中如何离开Python环境(linux怎么退出python)
- python中定义结构体的方法
- Python程序设计入门(5)类的使用简介
- python中将字典转换成其json字符串
- python快速查找算法应用实例