Python 3.6+hashlibfunction
hashlib.shake_256()
hashing
The SHAKE256 hash from the SHA-3 family with an output of any length and up to 256 bits of security; you pass the length in bytes to digest(n) and hexdigest(n).
Syntax
hashlib.shake_256(data=b'', *, usedforsecurity=True).hexdigest(length)
It differs from shake_128() only in the security ceiling, not in output length: both will produce a megabyte if asked. So shake_256(...).hexdigest(8) is no stronger than shake_128(...).hexdigest(8) — a short output limits security more than the choice of function does. The length in hexdigest(n) is in bytes, you get 2n characters.
Examples
import hashlib
h = hashlib.shake_256(b'abc')
print(h.hexdigest(8)) # → 483366601360a877
print(len(h.digest(100))) # → 100
See also
Open in the full glossarydocs.python.orgReport an inaccuracy