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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • springboot使用h2数据库做单元测试_h2数据库对接SQL

    springboot使用h2数据库做单元测试_h2数据库对接SQLh2数据库很方便,不用安装,我们在springboot项目中添加相关依赖就可以了。maven配置<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId>

    2022年10月9日
    3
  • LaTeX的安装教程(Texlive 2020 + TeX studio)

    LaTeX的安装教程(Texlive 2020 + TeX studio)LaTeX安装步骤1、TexLive安装1.1下载TexLive1.2安装TexLive1、TexLive安装1.1下载TexLive点击TexLive使用清华镜像进行下载。如下图所示。1.2安装TexLive1.2.1打开下载后的.ISO文件,如下图所示。以管理员身份运行install-tl-windows.bat文件。1.2.2运行后的界面如下图所示。软件的安装路径默认为C盘,这里可以修改为其他磁盘。1.2.3修改好软件的安装路径后,点击Advanced,

    2022年6月11日
    51
  • Java安全之Commons Collections2分析

    Java安全之CommonsCollections2分析首发:Java安全之CommonsCollections2分析0x00前言前面分析了CC1的利用链,但是发现在CC1的利用链中是有版

    2021年12月12日
    49
  • 领悟@Page指令中的AutoEventWireup

    领悟@Page指令中的AutoEventWireupAsp.NET中可以修改AutoEventWireup=”true”,使页面与某些特殊的事件方法绑定,自动识别这些具有特定名称的事件,而不需要进行委托。这些特定名称包括:Page_Init,Page_Load,Page_DataBind,Page_PreRender和Page_Unload等。.aspx设置AutoEventWireup=false情况下,Pag…

    2022年5月27日
    42
  • js中document.getElementById()用法「建议收藏」

    js中document.getElementById()用法「建议收藏」dom标准里面的 获取当前文档中指定id的元素if(document.getElementById(“regjm”).value!=document.getElementById(“regjm1”).value){  alert(“提示:请输入有效的认证码”);  document.getElementById(“regjm1”).focus();  retur

    2022年7月15日
    24
  • VS2013下串口数据char型转COleVariant问题[通俗易懂]

    VS2013下串口数据char型转COleVariant问题[通俗易懂]在串口需要发送一串字符数组buf[]时,COleVariant(buf)强制转换失效(在vc6.0环境中是允许的)。在VS2013环境下需要借助CByteArray类型进行中间的装换,实现代码如下:首先定义:CByteArraym_array;将char型数组中的数值赋值到m_array中 for(inti=0;im_array[i]=sbuf[i]; 

    2022年7月18日
    17

发表回复

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

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