Felipe Hoffa
Felipe Hoffa

Reputation: 59225

Match Snowflake MD5 to Python MD5

I'm trying to match the MD5 output from Snowflake md5_number_lower64 to the MD5 output in Python for the same string.

What's the code to pull this off?

Upvotes: 3

Views: 640

Answers (1)

Felipe Hoffa
Felipe Hoffa

Reputation: 59225

A quick example (from a teammate) to pull this off. In Python:

import hashlib
def md5_number_lower64(msg):
    return int.from_bytes(hashlib.md5(msg.encode('utf-8')).digest()[8:], 'big')

returns:

$ print(md5_number_lower64('Snowflake'))
> 9203306159527282910`

which matches Snowflake's result:

select md5_number_lower64('Snowflake');
-- 9203306159527282910

Docs:

Returns a 64 bit unsigned integer that represents the lower 64 bits of the message digest. This representation is useful for maximally efficient storage and comparison of MD5 digests.

Upvotes: 3

Related Questions