manbytesgnu_site

Source files for manbytesgnu.org
git clone git://holbrook.no/manbytesgnu_site.git
Info | Log | Files | Refs

generate.py (545B)


      1 # external imports
      2 import sha3
      3 
      4 
      5 class LogBloom:
      6 
      7     def __init__(self):
      8         self.content = bytearray(256)
      9 
     10 
     11     def add(self, element):
     12         if not isinstance(element, bytes):
     13             raise ValueError('element must be bytes')
     14         h = sha3.keccak_256()
     15         h.update(element)
     16         z = h.digest()
     17 
     18         for j in range(3):
     19             c = j * 2
     20             v = int.from_bytes(z[c:c+2], byteorder='big')
     21             v &= 0x07ff
     22             m = 255 - int(v / 8)
     23             n = v % 8
     24             self.content[m] |= (1 << n)