-
Notifications
You must be signed in to change notification settings - Fork 62
/
murmur.py
33 lines (25 loc) · 978 Bytes
/
murmur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from refinery.lib.murmur import mmh128digest32, mmh128digest64, mmh32digest
from refinery.units.crypto.hash import HashUnit, arg
class MurMurHash(HashUnit, abstract=True):
def __init__(self, seed: arg.number(help='optional seed value') = 0, text=False):
super().__init__(seed=seed, text=text)
class mmh32(MurMurHash):
"""
Returns the 32bit Murmur Hashof the input data.
"""
def _algorithm(self, data: bytes) -> bytes:
return mmh32digest(data, self.args.seed)
class mmh128x64(MurMurHash):
"""
Returns the 128bit Murmur Hash of the input data, 64bit variant.
"""
def _algorithm(self, data: bytes) -> bytes:
return mmh128digest64(data, self.args.seed)
class mmh128x32(MurMurHash):
"""
Returns the 128bit Murmur Hash of the input data, 64bit variant.
"""
def _algorithm(self, data: bytes) -> bytes:
return mmh128digest32(data, self.args.seed)