def generate_next_short_code(cls): base_id = Link.count_all() short_code = base62.hash(base_id + 1) while Link.query.filter(cls.short_code == short_code).count() > 0: base_id += 1 short_code = base62.hash(base_id) return short_code
# Base decode encoded string. print(base36.decode('5K')) print(base52.decode('3r')) print(base56.decode('5a')) print(base58.decode('4T')) print(base62.decode('3E')) print(base94.decode('#-')) # Base hash an integer/long # Takes an option param, length, which is defaulted to # basehash.base.HASH_LENGTH print(base36.hash(200)) print(base52.hash(200)) print(base56.hash(200)) print(base58.hash(200)) print(base62.hash(200)) print(base94.hash(200)) # Base unhash hashed string. print(base36.unhash('LUEREG')) print(base52.unhash('bXmcJ8')) print(base56.unhash('byvT3s')) print(base58.unhash('cCGYMV')) print(base62.unhash('bcWuqW')) print(base94.unhash('Z$_P7y')) # Get maximum number for hashing by `length` print(base36.maximum(HASH_LENGTH)) print(base52.maximum(25)) print(base56.maximum(10)) print(base58.maximum())
def test_base62_hash_fail_with_56800235584_6(): assert base62.hash(56800235584, 6)
def test_base62_hash_with_1234567890_10_RERZ0NM8Na(): assert base62.hash(1234567890, 10) == 'RERZ0NM8Na'
# Base decode encoded string. print base36.decode("5K") print base52.decode("3r") print base56.decode("5a") print base58.decode("4T") print base62.decode("3E") print base94.decode("#-") # Base hash an integer/long # Takes an option param, length, which is defaulted to # basehash.base.HASH_LENGTH print base36.hash(200) print base52.hash(200) print base56.hash(200) print base58.hash(200) print base62.hash(200) print base94.hash(200) # Base unhash hashed string. print base36.unhash("LUEREG") print base52.unhash("bXmcJ8") print base56.unhash("byvT3s") print base58.unhash("cCGYMV") print base62.unhash("bcWuqW") print base94.unhash("Z$_P7y") # Get maximum number for hashing by `length` print base36.maximum(HASH_LENGTH) print base52.maximum(25) print base56.maximum(10) print base58.maximum()
# Base decode encoded string. print base36.decode('5K') print base52.decode('3r') print base56.decode('5a') print base58.decode('4T') print base62.decode('3E') print base94.decode('#-') # Base hash an integer/long # Takes an option param, length, which is defaulted to # basehash.base.HASH_LENGTH print base36.hash(200) print base52.hash(200) print base56.hash(200) print base58.hash(200) print base62.hash(200) print base94.hash(200) # Base unhash hashed string. print base36.unhash('LUEREG') print base52.unhash('bXmcJ8') print base56.unhash('byvT3s') print base58.unhash('cCGYMV') print base62.unhash('bcWuqW') print base94.unhash('Z$_P7y') # Get maximum number for hashing by `length` print base36.maximum(HASH_LENGTH) print base52.maximum(25) print base56.maximum(10) print base58.maximum()