File: fnv.py

package info (click to toggle)
python-flor 1.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 108 kB
  • sloc: python: 183; sh: 6; makefile: 5
file content (24 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# DCSO - Flor
# Copyright (c) 2016, 2017, DCSO GmbH. All rights reserved.

offset = 14695981039346656037
prime = 1099511628211

def fnv_1(value):
    if not isinstance(value, bytes):
        raise TypeError("Value must be a bytes object!")
    hash = offset
    for byte in bytearray(value):
        hash = (hash*prime) & 0xFFFFFFFFFFFFFFFF
        hash ^= byte
    return hash

def fnv_1a(value):
    if not isinstance(value, bytes):
        raise TypeError("Value must be a bytes object!")
    hash = offset
    for byte in bytearray(value):
        hash ^= byte
        hash = (hash*prime) & 0xFFFFFFFFFFFFFFFF
    return hash