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


相关推荐

  • 详解-脏读、幻读与不可重复读

    详解-脏读、幻读与不可重复读

    2022年2月17日
    49
  • Spring日志管理

    Spring日志管理SpringBoot关于日志的官方文档1、简述SpringBoot官方文档关于日志的整体说明本博客基于SpringBoot_1.3.6大家请先简单看下这篇英文的官方文档,文中有说 SpringBoot 内部日志系统使用的是 CommonsLogging 并且 SpringBoot 给 JDKLogging , Log4j2(Log4j也是支持的) , Lo

    2022年5月17日
    42
  • Vue(9)购物车练习

    Vue(9)购物车练习购物车案例经过一系列的学习,我们这里来练习一个购物车的案例**需求:**使用vue写一个表单页面,页面上有购买的数量,点击按钮+或者-,可以增加或减少购物车的数量,数量最少不得少于0,点击移除按钮

    2022年7月30日
    9
  • java读写锁实现原理_java可重入锁原理

    java读写锁实现原理_java可重入锁原理一、synchronized和ReentrantLock的对比到现在,看到多线程中,锁定的方式有2种:synchronized和ReentrantLock。两种锁定方式各有优劣,下面简单对比一下:1、synchronized是关键字,就和if…else…一样,是语法层面的实现,因此synchronized获取锁以及释放锁都是Java虚拟机帮助用户完成的;ReentrantLock是类层面的…

    2022年8月12日
    9
  • 选择有这些特点的it行业人力外包公司没错

    选择有这些特点的it行业人力外包公司没错互联网的快速发展加快了传统企业信息化进程,很多传统企业自己组建软件技术部,既缺少技术开发经验,又缺乏软件项目管理经验,因此软件外包成为这些公司的首选。但完全的项目外包,使得其与软件外包公司的沟通变的不畅通,软件外包公司又缺乏传统企业的业务经验,且保密性很差,所以不少传统企业会选择和it行业人力外包公司合作来引进it人才,那么什么样的it行业人力外包公司值得选择?一、选择有一定年限的it行业人力外包公司为什么要选择一个成立时间长的it行业人力外包公司呢?因为it行业人力外包公司成立的时间越长,越能

    2022年5月19日
    47
  • golang 2021.5 激活码(最新序列号破解)

    golang 2021.5 激活码(最新序列号破解),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    257

发表回复

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

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