Testing with SHA1 gives positive results, also changed the truncation rule

This commit is contained in:
thecookingsenpai 2024-02-02 16:31:18 +01:00
parent f0a8aa02a9
commit f66bca67ac

View File

@ -34,4 +34,9 @@ def create_hash(*args: str, decode=False, limit=10) -> str:
str_ = str_.encode("utf-8")
str_ = hashlib.sha1(str_).hexdigest()
# REVIEW Switched to sha1 hashlib.sha256(str_).hexdigest()
return str_[-limit:]
# REVIEW Take the first limit/2 and last limit/2 characters
# This is to avoid collisions
return str_[:limit // 2] + str_[-limit // 2:] if limit % 2 == 0 else str_[:limit // 2] + str_[-limit // 2 - 1:]
# return str_[-limit:]