import secrets from functools import partial try: from hashlib import scrypt uid_hash = partial(scrypt, n=16384, r=8, p=1) except ImportError: # Python 3.5 has to use external py-scrypt package from pypi from scrypt import hash as scrypt uid_hash = partial(scrypt, N=16384, r=8, p=1) # print(secrets.token_urlsafe()) UID_SALT = "hkRXwLlQKmCJoy5qaahp" def hash_uid(uid: str, salt: str = UID_SALT) -> str: return uid_hash(bytes.fromhex(uid), salt=salt.encode()).hex() if __name__ == "__main__": UID = "01 23 AD F0" ch = hash_uid(UID) h = 'a6d9ba36ecb5f8e6312f40ee260ad59e9cca3c6ce073bf072df3324c0072886196e6823a7c758ab567fc53e91fbbda297a4efe0072e41316c56446ef126a5180' print("UID:", UID) print("hash:", ch) print("correct", ch == h)