I have got cached instance of hasher:
m1 = hashlib.md5()
m1.update(b'very-very-long-data')
cached_sum = m1
and I would like to update external hasher with a sum cached before:
def append_cached_hash(external_hasher):
# something like this
external_hasher.update(cached_sum)
Unfortunately, it does not work as update() expects bytes. I could pass the same 'very-very-long-data' bytes again, but it refuses the whole idea of pre-caching md5 sum for common long-data object.
I could do something like the following:
external_hasher.update(cached_sum.hexdigest())
However, it does not produce the same needed result as:
external_hasher.update(b'very-very-long-data')
How could I implement the function above?
The same problem can be formulated differently. There are 3 big data sets and it is necessary to calculate md5 sums using python for all possible combinations. It is allowed to calculate md5 once for each data source.
m1 = hashlib.md5(b'very-big-data-1')
m2 = hashlib.md5(b'very-big-data-2')
m3 = hashlib.md5(b'very-big-data-3')
What should I write in the second parameter of the following print functions to achieve the goal?
print("sum for data 1 and data 2 is:", m1.update(m2))
print("sum for data 1 and data 3 is:", m1.update(m3))
print("sum for data 2 and data 3 is:", m2.update(m3))
print("sum for data 1, data 2 and data 3 is:", m1.update(m2.update(m3)))
Thanks in advance for your help!