I'm trying to generate the same MD5 codes from Python 3 and SQL but I get always a different result.
With this Unique Identifier f033b004-eb80-412d-9773-f4f06bb994c1
SELECT HASHBYTES('MD5', 'f033b004-eb80-412d-9773-f4f06bb994c1')
Result: 0x9BCE8D23CAC76AF4F61C04673CDD0081
And then I do that calculation
SELECT ABS(HASHBYTES('MD5', 'f033b004-eb80-412d-9773-f4f06bb994c1') % 10)
Result: 5
Now with python I use the hashlib
library
import hashlib
m = hashlib.md5('f033b004-eb80-412d-9773-f4f06bb994c1'.encode() )
m.digest(), m.hexdigest()
Result: b'\x9b\xce\x8d#\xca\xc7j\xf4\xf6\x1c\x04g<\xdd\x00\x81',
'9bce8d23cac76af4f61c04673cdd0081'
And then I do the same calculations
int.from_bytes( b'\x9b\xce\x8d#\xca\xc7j\xf4\xf6\x1c\x04g<\xdd\x00\x81',
byteorder='big',
signed=False )%10
Result: 9
Does anyone knows how can I get from the Python code the same results as the SQL Server ?