python实现HMAC算法与应用[通俗易懂]

python实现HMAC算法与应用[通俗易懂]Inthisprogram,youarerequiredtoinvokethealgorithmsthatareimplementedinbuild-inlibrary.Yourprogramdoesthefollowing:ExampleInputExampleOutputsolutioncodeoutput受于文本篇幅原因,本文相关算法实现工程例如环境及相关库,无法展示出来,现已将资源上传,可自行点击下方链接下载。python实现Hash和H

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

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

Jetbrains全家桶1年46,售后保障稳定

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
在这里插入图片描述

受于文本篇幅原因,本文相关算法实现工程例如环境及相关库,无法展示出来,现已将资源上传,可自行点击下方链接下载。

python实现Hash和HMAC算法工程文件

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/215911.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 定位?

    定位?

    2021年6月18日
    96
  • MongoDB启动失败原因「建议收藏」

    MongoDB启动失败原因「建议收藏」MongoDB启动失败原因今天某个项目突然登录不了,查看服务器发现是后端出现异常,停掉后端重新启动的时候失败,显示是数据库连接失败,然后接着查看数据库,发现数据库连接失败,原因是数据库挂掉了。数据库用的是MongoDB,我也只是听过还没有使用过,简单的在网上查询了一下MongoDB的启动命令就直接开始启动了,结果发现启动失败。尝试了好一些方法后才终于成功启动:尝试提升MongoDB所在文…

    2025年6月21日
    6
  • 如何使用ccs软件创建工程

    这里简叙如何使用ccs软件创建工程的具体步骤,正文如下:1、打开ccs软件,单击菜单栏中的“Project”选项,在弹出的下拉菜单中选择“NewCCSProject”,如下图所示:  2、在“Projectname”中输入自定义的工程名称,在“Family”中选择所需DSP的系列,在“Variant”的目录下选择所需的DSP的型号,最后在“Connection”目录下选择仿真…

    2022年4月8日
    410
  • java分页代码_基本分页存储管理java代码

    java分页代码_基本分页存储管理java代码在java项目中不使用mybatis的pageHelper进行数据分页:1.分页工具类编写:importjava.util.List;publicclassPageModel<E>{//结果集privateList<E>list;//查询记录数privateinttotalRecords;…

    2022年10月3日
    1
  • oracle数据库recover和restore的区别

    oracle数据库recover和restore的区别

    2021年9月1日
    108
  • python处理亿级大数据(rar暴力破解器安卓版)

    转载请注明出处:https://blog.csdn.net/l1028386804/article/details/85566045今天是2019年元旦,首先祝大家元旦快乐,在这个喜庆的日子里,不知道大家有没有坚持研究自己所在领域的知识。其实,每项知识、技能的积累,需要的是日复一日的坚持,正所谓——持之以恒,贵在坚持,这样才能做到每天进步一点点。好了,步入正题,今天,闲来无事,基于Python…

    2022年4月15日
    51

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号