calculate hash in Python