class Hashedbitset(): def __init__(self, size): self._value = Bitset(size) self._size = size self._hasher = Hasher() def Add(self, item): self._value.Add(self._hasher.hash(item, 1)[0]) def Size(self): return self._value.Size() def Contains(self, item): n = self._hasher.hash(item, 1)[0] return self._value.Contains(n)
class Bloomfilter(): def __init__(self, size, keys): self._value = Bitset(size) self._size = size self._keys = keys self._hasher = Hasher() def Add(self, item): [self._value.Add(i) for i in self._hasher.hash(item, self._keys)] def Size(self): return self._value.Size() def Contains(self, item): n = self._hasher.hash(item, self._keys) for i in n: if not self._value.Contains(i): return False return True
from hasher import Hasher hasher = Hasher('') print(hasher.hash('my name is jack'))
def _derive_key(key, salt=get_random_bytes(32)): h = Hasher(10) return h.hash(key, salt)[-32:], salt