Skip to content

Instantly share code, notes, and snippets.

@humblewolf
Created April 5, 2022 10:15
Show Gist options
  • Save humblewolf/2c19b5f0dc83bb783fac8490a5517ca5 to your computer and use it in GitHub Desktop.
Save humblewolf/2c19b5f0dc83bb783fac8490a5517ca5 to your computer and use it in GitHub Desktop.
import hashlib
import timeit
print(hashlib.algorithms_available)
print(hashlib.algorithms_guaranteed)
# hashing functions -------
def sha256fun(binp):
h = hashlib.sha256(binp)
return h.hexdigest()
def blake2bfun(binp):
h = hashlib.blake2b(binp)
return h.hexdigest()
def blake2bfunWSalt(binp):
h = hashlib.blake2b(binp, person=b'joker')
return h.hexdigest()
def blake2sfun(binp):
h = hashlib.blake2s(binp)
return h.hexdigest()
# ---------------------------
# plain_text = 'amar😀' * 100
plain_text = 'amar' * 100
print(plain_text)
ptenc = plain_text.encode('utf-8')
print(ptenc)
print("----------------")
print("----------------")
print("----------------")
#----------------
# print(h.hexdigest())
# print(h.digest())
# print(h.digest_size)
# print(h.block_size)
print(sha256fun(ptenc))
print(blake2bfun(ptenc))
print(blake2bfunWSalt(ptenc))
print(blake2sfun(ptenc))
print("----------------")
print("----------------")
print("----------------")
t1 = timeit.Timer('sha256fun(ptenc)', "from __main__ import sha256fun, ptenc")
t2 = timeit.Timer('blake2bfun(ptenc)', "from __main__ import blake2bfun, ptenc")
t4 = timeit.Timer('blake2bfunWSalt(ptenc)', "from __main__ import blake2bfunWSalt, ptenc")
t3 = timeit.Timer('blake2sfun(ptenc)', "from __main__ import blake2sfun, ptenc")
# print("sha256 - {}".format(t1.timeit(1000000)))
# print("blake2b - {}".format(t2.timeit(1000000)))
print("sha256 - {}".format(t1.repeat()))
print("blake2b - {}".format(t2.repeat()))
print("blake2b w salt - {}".format(t4.repeat()))
print("blake2s - {}".format(t3.repeat()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment