A 32-bit hash function based on SHA1. Args: data (bytes): the data to generate 32-bit integer hash from. Returns: int: an integer hash value that can be encoded using 32 bits.
(data)
| 6 | import struct |
| 7 | |
| 8 | def sha1_hash32(data): |
| 9 | """A 32-bit hash function based on SHA1. |
| 10 | |
| 11 | Args: |
| 12 | data (bytes): the data to generate 32-bit integer hash from. |
| 13 | |
| 14 | Returns: |
| 15 | int: an integer hash value that can be encoded using 32 bits. |
| 16 | """ |
| 17 | return struct.unpack('<I', hashlib.sha1(data).digest()[:4])[0] |
| 18 | |
| 19 | |
| 20 | # The size of a hash value in number of bytes |