在python实现中的Sha-3

在python实现中的Sha-3,第1张

概述我试图在 python中实现sha-3.下面给出的代码是我如何实现它.但我一次又一次得到以下错误. import sys import hashlibarg1 = sys.argv[1]with open(arg1, 'r') as myfile: data=myfile.read().replace('\n', '')import sha3s=hashlib.sha3_228 我试图在 python中实现sha-3.下面给出的代码是我如何实现它.但我一次又一次得到以下错误.

import sys import hashlibarg1 = sys.argv[1]with open(arg1,'r') as myfile:     data=myfile.read().replace('\n','')import sha3s=hashlib.sha3_228(data.encode('utf-8')).hexdigest()print(s)

以下错误是我执行时得到的错误.

Traceback (most recent call last):file "sha3.py",line 6,in <module>import sha3file "/home/hello/documents/SHA-3/sha3.py",line 7,in <module>s=hashlib.sha3_228(data.encode('utf-8')).hexdigest()AttributeError: 'module' object has no attribute 'sha3_228'

以下链接可供参考.
https://pypi.python.org/pypi/pysha3

解决方法 这里有两个问题:一个来自您的代码,一个来自文档,其中包含您想要使用的函数的拼写错误.

您正在调用hashlib库中不存在的函数.您想从包含pysha3的模块sha3调用函数sha3_228.实际上,sha3_228不存在,存在sha3_224.

只需用sha3.sha3_224替换hashlib.sha3_228即可.

并确保已使用命令安装了pysha3

python -m pip install pysha3

这是一个例子

import sha3data='maydata's=sha3.sha3_224(data.encode('utf-8')).hexdigest()print(s)# 20faf4bf0bbb9ca9b3a47282afe713ba53c9e243bc8bdf1d670671cb
总结

以上是内存溢出为你收集整理的在python实现中的Sha-3全部内容,希望文章能够帮你解决在python实现中的Sha-3所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1193985.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-03
下一篇2022-06-03

发表评论

登录后才能评论

评论列表(0条)

    保存