Created
March 19, 2019 08:18
-
-
Save olivernadj/93e134e96b2c35a5400b6b3127a06be9 to your computer and use it in GitHub Desktop.
Growatt hash_password performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
def hash_password_str(password): | |
password_md5 = hashlib.md5(password.encode("utf-8")).hexdigest() | |
for i in range(0, len(password_md5), 2): | |
if password_md5[i] == "0": | |
password_md5 = password_md5[0:i] + "c" + password_md5[i + 1 :] | |
return password_md5 | |
def hash_password_byte(password): | |
password_md5 = bytearray(hashlib.md5(password.encode("utf-8")).digest()) | |
for i in range(0, len(password_md5)): | |
if password_md5[i] < 0x10: | |
password_md5[i] += 0xc0 | |
return ''.join('{:02x}'.format(x) for x in password_md5) | |
timeit.timeit("hash_password_str('*****')", number=1000, setup="from __main__ import hash_password_str") | |
#0.002764114000456175 | |
timeit.timeit("hash_password_byte('*****')", number=1000, setup="from __main__ import hash_password_byte") | |
#0.013364751999688451 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment