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)
上一篇 2025年7月12日 上午11:43
下一篇 2025年7月12日 下午12:15


相关推荐

  • ODA(Open Design Alliance)介绍「建议收藏」

    ODA(Open Design Alliance)介绍「建议收藏」注:与autocad兼容的软件,大部分基于Intellicad,另外刚冒出一个bricscad,天河的PCCADV10就是基于bricscad,bricscad是用ODA的库开发的,而开发brics

    2022年8月6日
    8
  • 使用 CSS 实现垂直居中的8种方法

    使用 CSS 实现垂直居中的8种方法CSS 垂直居中的 8 种方法目录 CSS 垂直居中的 8 种方法 1 通过 verticle align middle 实现 CSS 垂直居中 2 通过 display flex 实现 CSS 垂直居中 3 通过伪元素 before 实现 CSS 垂直居中 4 通过 display table cell 实现 CSS 垂直居中 5 通过隐藏节点实现 CSS 垂直居中 6 已知父元素高度通过 transform 实现 CSS 垂直居中 7 到垂直居中的位置 8 通过 line height 实现

    2026年3月16日
    2
  • sqrt函数原型c语言,C语言sqrt函数的实例用法讲解

    sqrt函数原型c语言,C语言sqrt函数的实例用法讲解前言继承是OOP设计中的重要概念。在C++语言中,派生类继承基类有三种继承方式:私有继承(private)、保护继承(protected)和公有继承(public)。一、继承规则继承是C++中的重要特性,派生2021-03-2218:02:41大家有没有在项目中遇到过,将一些预定义的本地结构体转换为Json字符串后,发送到网络中的情形。那我猜想下大家常规的做法:写一个函数,传入结构体的指针,然后…

    2022年5月1日
    76
  • python字符串转化列表_Python列表到字符串的转换[通俗易懂]

    python字符串转化列表_Python列表到字符串的转换[通俗易懂]python字符串转化列表Sometimeswewanttoconvertthelisttoastringsothatwecanprintitorlogitfordebuggingpurposes.Inthistutorial,wewilllearnhowtoconvertalisttostringinaPythonpro…

    2022年5月10日
    43
  • 智谱 AI 发布开源 GLM 模型家族:MIT 许可、Z.ai 平台与高速推理服务同步亮相

    智谱 AI 发布开源 GLM 模型家族:MIT 许可、Z.ai 平台与高速推理服务同步亮相

    2026年3月12日
    3
  • 敏感词过滤golang

    敏感词过滤golangnbsp 用 golang 写了敏感词过滤的工具 主要用来检测用户昵称中是否存在敏感词 同时提供剔除转移字符的功能 可以先将敏感词库存放在一个 map 中 敏感词可以参考这里 https github com fwwdn sensitive stop words 将 map 和昵称传入 程序会检查昵称的每一个子串 判断是否在 map 敏感词库中 复杂度 O len name 2 packageutil

    2026年3月17日
    2

发表回复

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

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