def keyScheduleRounds(self, inputkey, inputround, desiredround, returnSubkeys=True): """Create the 16 subkeys K[1] to K[16] from the given key""" if inputround == 0: inputkey = bytearray2binarylist(inputkey, 8) key = self.__permutate(self.__pc1, inputkey) else: inputkey = bytearray2binarylist(inputkey, 6) key = self.__permutate(self.__pc2_inv, inputkey) i = inputround L = key[:28] R = key[28:] while i < desiredround: i += 1 j = 0 # Perform circular left shifts while j < self.__left_rotations[i]: L.append(L[0]) del L[0] R.append(R[0]) del R[0] j += 1 while i > desiredround: # Perform circular right shifts j = 0 while j < self.__left_rotations[i]: L.insert(0, L[27]) del L[28] R.insert(0, R[27]) del R[28] j += 1 i -= 1 if desiredround == 0: key = self.__permutate(self.__pc1_inv, L + R) return binarylist2bytearray(key, 8) if returnSubkeys else key else: key = self.__permutate(self.__pc2, L + R) return binarylist2bytearray(key, 6) if returnSubkeys else key
def sbox_in_first_fbox(self, pt, guess, bnum): init=bytearray2binarylist(pt, 8) initPermut = self.__permutate(self.__ip, init) R = initPermut[32:] expR = self.__permutate(self.__expansion_table, R) expR = expR[bnum*6:(1+bnum)*6] guess = np.unpackbits(np.uint8(guess)) guess = guess[2:] B = list(map(lambda x, y: x ^ y, expR, guess)) return B
def keyScheduleRounds(self, inputkey, inputround, desiredround, returnSubkeys=True): """Create the 16 subkeys K[1] to K[16] from the given key""" if inputround == 0: inputkey = bytearray2binarylist(inputkey,8) key = self.__permutate(self.__pc1, inputkey) else: inputkey = bytearray2binarylist(inputkey,6) key = self.__permutate(self.__pc2_inv, inputkey) i = inputround L = key[:28] R = key[28:] while i < desiredround: i += 1 j = 0 # Perform circular left shifts while j < self.__left_rotations[i]: L.append(L[0]) del L[0] R.append(R[0]) del R[0] j += 1 while i > desiredround: # Perform circular right shifts j = 0 while j < self.__left_rotations[i]: L.insert(0,L[27]) del L[28] R.insert(0,R[27]) del R[28] j += 1 i -= 1 if desiredround==0: key = self.__permutate(self.__pc1_inv, L + R) return binarylist2bytearray(key, 8) if returnSubkeys else key else: key = self.__permutate(self.__pc2, L + R) return binarylist2bytearray(key, 6) if returnSubkeys else key