2

I'm using following code to get the keccak 256 hash:

import sha3
k = sha3.keccak_256()
k.update(b'age')
print (k.hexdigest())

How do I convert the keccak 256 hash value back to original string? (I'm ok with using any library as needed).

aste123
  • 1,223
  • 4
  • 20
  • 40
  • 3
    SHA3 is one way hash function i.e. an input `x` after running through a function `f(x)` results in an output `y` where `x --> y` is easy and `y --> x` is computationally very expensive to perform (to the order of billions of years). If what you're asking for is possible i.e. hash to original string, the hash function would be considered as broken. Here's a resource which might help: https://en.wikipedia.org/wiki/Cryptographic_hash_function – Sudheesh Singanamalla Jun 07 '21 at 16:19
  • 1
    Even if you could reverse a SHA3 hash, how would you determine which of the theoretically infinite inputs is the one you want? – JonSG Jun 07 '21 at 16:27
  • ModuleNotFoundError: No module named 'sha3' even after pip install – rsc05 Jul 23 '22 at 17:48

1 Answers1

8

You can't convert the hash value back to the original string. The hash function is created in a way that it is infeasible to convert the hash value back to the original string.

Tom Lee
  • 360
  • 1
  • 3
  • 10
  • 3
    It's not just very hard -it's impossible because many many different strings will give the same hash value. To get from an arbitrary length string to 256 bits you have thrown away a lot of data that cannot be recovered. – neil Jun 07 '21 at 16:24
  • infinitely many – Rob Feb 14 '23 at 06:04