Sha-3 in python implementation
I am trying to implement sha-3 in python. Below is the code how I implemented it. But I am getting below error over and over again.
import sys
import hashlib
arg1 = sys.argv[1]
with open(arg1, 'r') as myfile:
data=myfile.read().replace('\n', '')
import sha3
s=hashlib.sha3_228(data.encode('utf-8')).hexdigest()
print(s)
The next error is what I get when I execute it.
Traceback (most recent call last):
File "sha3.py", line 6, in <module>
import sha3
File "/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'
Below is the link for reference. https://pypi.python.org/pypi/pysha3
source to share
There are two problems here, one from your code and one from the documentation, which contains a typo for the function you would like to use.
You are calling a function that is not in the library hashlib
. You want to call a function sha3_228
from a module sha3
that comes with the package pysha3
. In fact, it sha3_228
does not exist, it does exist sha3_224
.
Just replace hashlib.sha3_228
with sha3.sha3_224
.
And make sure you installed pysha3
with the command
python -m pip install pysha3
Here's an example
import sha3
data='maydata'
s=sha3.sha3_224(data.encode('utf-8')).hexdigest()
print(s)
# 20faf4bf0bbb9ca9b3a47282afe713ba53c9e243bc8bdf1d670671cb
source to share