I'm trying to convert an MD5 hashed value into a a bit integer in python. Does anyone have any idea how I would go about doing this?
I currently go through several ngrams applying a hash to each ngram:
for sentence in range(0,len(doc)):
for i in range(len(doc[sentence]) - 4 + 1):
ngram = doc[sentence][i:i + 4]
hashWord = hashlib.md5()
hashWord.update(ngram)
Thanks for any help.
hexdigest() Like digest() except the digest is returned as a string object of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.
As a python programmer, we need hash functions to check the duplicity of data or files, to check data integrity when you transmit data over a public network, storing the password in a database etc. MD5 - MD5 or message digest algorithm will produce a 128-bit hash value.
If by "into bits", you mean a bit string for instance, then something like:
import hashlib
a = hashlib.md5('alsdkfjasldfjkasdlf')
b = a.hexdigest()
as_int = int(b, 16)
print bin(as_int)[2:]
# 11110000110010001100111010111001011010101011110001010000011010010010100111100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With