Пример #1
0
 def test_decode_hex(self):
     hex_str = '507f1f77bcf86cd799439011'
     assert Hashids().decode_hex('y42LW46J9luq3Xq9XMly') == hex_str
     h = Hashids(min_length=1000)
     assert h.decode_hex(h.encode_hex(hex_str)) == hex_str
     assert Hashids().decode_hex('WxMLpERDrmh25Lp4L3xEfM6WovWYO3IjkRMKR2ogCMVzn4zQlqt1WK8jKq7OsEpy2qyw1Vi2p') == \
            'f000000000000000000000000000000000000000000000000000000000000000000000000000000000000f'
Пример #2
0
 def test_decode_hex(self):
     hex_str = '507f1f77bcf86cd799439011'
     assert Hashids().decode_hex('y42LW46J9luq3Xq9XMly') == hex_str
     h = Hashids(min_length=1000)
     assert h.decode_hex(h.encode_hex(hex_str)) == hex_str
     assert Hashids().decode_hex('WxMLpERDrmh25Lp4L3xEfM6WovWYO3IjkRMKR2ogCMVzn4zQlqt1WK8jKq7OsEpy2qyw1Vi2p') == \
            'f000000000000000000000000000000000000000000000000000000000000000000000000000000000000f'
Пример #3
0
def generate_hash(data, alphabet=DEFAULT_ALPHABET):
    """
    Currently this uses md5 to generate a 32 byte string. This
    a 256 bit value and then use hashid to convert this to a hash using
    the alphabet above
    Args:
        data: string
        alphabet: the alphabet to use for the hash
    """
    hashids = Hashids(alphabet=alphabet)
    md5 = hashlib.md5(data)
    return hashids.encode_hex(md5.hexdigest())
Пример #4
0
def id_from_string(string, key):
    val = []
    if (len(string) > 64):
        string = string[0:63]
    if (len(string) < 64):
        string += (64 - len(string)) * "."
    for char in string:
        tempstr = char.encode("utf-8")
        val.append(tempstr.hex())
    tmp = ''.join(val)
    hashids = Hashids(salt=key)
    return (hashids.encode_hex(tmp))