def generate_sub_keys(self, key): """ Generate 48 bit sub keys from the provided 56 bit key. The function will generate a list of length n, where n is the number of rounds, containing the sub keys. :param key: 56 bit key. :return: list of length n, where n is the number of rounds, containing the sub keys. """ sub_keys = [] left, right = bitutils.split_list(key) for i in range(self.number_of_rounds): left = bitutils.rotate(left, -DES.key_shifts[i]) right = bitutils.rotate(right, DES.key_shifts[i]) shifted_key = left + right sub_key = self.permute(shifted_key, DES.PC2) sub_keys.append(sub_key) return sub_keys
def encrypt_round(self, block, round_key): """ Encrypts a block of 64 bits using a Feistel network of n rounds. The number of rounds is specified in the constructor. :param block: block to be encrypted. :param round_key: key to be used in the current round. :return: the encrypted block. """ left, right = bitutils.split_list(block) f = self.round_function(right, round_key) next_left = right next_right = left ^ f return next_left + next_right