Bug in Python Whirlpool library

Asked

Viewed 30 times

1

I installed the Whirlpool library in Python 3.6.5 and Python 2.7.9 to compute hashes with it. However, she presented an unusual problem: in conjunction with other libraries, it works, and when it’s alone, it doesn’t. Inserted into this code, in Python 2.7.9, it works:

from Crypto.Hash import SHA512
from Crypto.Hash import SHA384
from Crypto.Hash import SHA256
from Crypto.Hash import SHA224
from Crypto.Hash import RIPEMD
from Crypto.Hash import MD5
from Crypto.Hash import MD4
from Crypto.Hash import MD2
import whirlpool
import hashlib

a = raw_input("Digite a string: ")
b = SHA512.new(a).hexdigest()
c = SHA384.new(a).hexdigest()
d = SHA256.new(a).hexdigest()
e = SHA224.new(a).hexdigest()
f = RIPEMD.new(a).hexdigest()
g = MD5.new(a).hexdigest()
h = MD4.new(a).hexdigest()
i = MD2.new(a).hexdigest()
j = whirlpool.new(a).hexdigest()
l = hashlib.sha1(a).hexdigest() 
print "SHA512 = ", b
print "SHA384 = ", c
print "SHA256 = ", d
print "SHA224 = ", e
print "RIPEMD160 = ", f
print "MD5 = ", g
print "MD4 = ", h
print "MD2 = ", i
print "Whirlpool = ", j
print "SHA1 = ", l

However, when I create the following program with her:

import whirlpool
a = raw_input("Digite a string: ")
j = whirlpool.new(a).hexdigest()
print "Whirlpool = ", j

it displays the following error message:

E:\>python whirlpool.py
Digite a string: sete
Traceback (most recent call last):
  File "whirlpool.py", line 1, in <module>
    import whirlpool
  File "E:\whirlpool.py", line 3, in <module>
    j = whirlpool.new(a).hexdigest()
AttributeError: 'module' object has no attribute 'new'

If in the previous program, he did not present problems with the attribute "new", why did he present it? Remember that in this case the attribute "new" is his own, not another library. I already uninstalled and installed the library again and the problem persists. What happens in this case?

  • 1

    Marcelo, did you run this other code on Python2? Because I ran the test here, and it worked perfectly.

  • Hello, Daniel! In Python 2 it worked, but in Python 3 it seems that there is some incompatibility. I changed the file name from "Whirlpool" to "Whirlpool-hash" and it worked, but only in Python 2.

1 answer

2


One thing that may be giving problem is that the file name is equal to the imported library name.

Try to rename the file and run again.

  • Thanks, Geraldo! It worked, but only in Python 2. Python 3 seems to have some incompatibility with the library.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.