I have a cached hasher instance:
m1 = hashlib.md5()
m1.update(b'very-very-long-data')
cached_sum = m1
and I would like to update an external hash with the amount cached to:
def append_cached_hash(external_hasher):
external_hasher.update(cached_sum)
Unfortunately, it does not work, since update () expects bytes. I could again pass the same “very, very, very long” bytes, but he abandons the idea of pre-caching md5 sum for a shared long-data object.
I could do something like the following:
external_hasher.update(cached_sum.hexdigest())
However, it does not produce the same necessary result as:
external_hasher.update(b'very-very-long-data')
How to implement the function above?
The same problem can be formulated in different ways. There are 3 large datasets, 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')
, ?
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)))
!