MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / random

Function random

src/Crypt/CryptHash.py:29–34  ·  view source on GitHub ↗
(length=64, encoding="hex")

Source from the content-addressed store, hash-verified

27
28
29def random(length=64, encoding="hex"):
30 if encoding == "base64": # Characters: A-Za-z0-9
31 hash = hashlib.sha512(os.urandom(256)).digest()
32 return base64.b64encode(hash).decode("ascii").replace("+", "").replace("/", "").replace("=", "")[0:length]
33 else: # Characters: a-f0-9 (faster)
34 return hashlib.sha512(os.urandom(256)).hexdigest()[0:length]
35
36
37# Sha512 truncated to 256bits

Callers

nothing calls this directly

Calls 2

digestMethod · 0.45
hexdigestMethod · 0.45

Tested by

no test coverage detected