def readNBytesAsBits(self, nbytes): bits = '' for i in xrange(nbytes): byte = self.readChar() byte_as_bits = utils.bits(byte, 8) bits += byte_as_bits return bits
def get(self, key=''): if not key: return False for one_hash in bits(self._size, self._matrix_list, key): for one_bit in one_hash: if not self._body[one_bit]: return False return True
def add(self, key): has_new = [] for one_hash in bits(self._size, self._matrix_list, key): for one_bit in one_hash: if not self._body[one_bit]: has_new.append(one_bit) self._body[one_bit] = 1 if len(has_new) > 0: self.save_to_storage(has_new) return True return False
def substitute(T): """ Apply SBoxes to a 48 bit input and return 32 bit output. """ sub = [] # The given 48 bit block is divided into eight 6 bit pieces for i, p in enumerate(utils.nsplit(T, 6)): # First and Last bit give the row of SBOX row = int(str(p[0]) + str(p[5]), 2) # And the other bits give the column col = int("".join([str(s) for s in p[1:][:-1]]), 2) sub += list(map(int, utils.bits(C.SBOX[i][row][col]))) return sub
def pack(self, value, bits): self.bits += utils.bits(value, bits)
def checkbit(i, width, start, end, expected): e = utils.bitrange(i, width, start, end) assert e == expected assert e == utils.bits2int(utils.bits(i, width)[start:end])