I’ve got a rather strange problem. For a Distributed Hash Table I need to be able to do some simple math operations on MD5 hashes. These include a sum (numeric sum represented by the hash) and a modulo operation. Now I’m wondering what the best way to implement these operations is.
I’m using hashlib to calculate the hashes, but since the hashes I get are then string, how do I calculate with them?
I’ve got a rather strange problem. For a Distributed Hash Table I need to
Share
You can use the
hexdigest()method to get hexadecimal digits, and then convert them to a number:If you already have the output of
digest(), you can convert it to hexadecimal digits:Edit:
For the second case, it’s actually easier to convert using
.encode('hex')orbinascii.hexlify: