When I try to use the hash function, it seems the update method doesn't overwrite the string:
For example, given a string magazine
hasher = hashlib.sha256() #set the hasher
hasher.update(magazine.encode('utf-8'))
print( int( hasher.hexdigest(), 16 ) % 10**8)
hasher.update(magazine.encode('utf-8'))
print( int( hasher.hexdigest(), 16 ) % 10**8)
will print 73983538 65808855
hasher = hashlib.sha256()
hasher.update(magazine.encode('utf-8'))
print( int( hasher.hexdigest(), 16 ) % 10**8)
hasher = hashlib.sha256() #reset the hasher
hasher.update(magazine.encode('utf-8'))
print( int( hasher.hexdigest(), 16 ) % 10**8)
will print
73983538
73983538
What exactly is the update function, and is there a way to reset the string without creating a new hasher?
Many thanks,