def _get_offset(self, message): initial_block_length = self._get_block_length(message) pad_size = 1 while True: padding_chars = [ random.choice(self.padding_chars) for _ in range(pad_size) ] padding = Concatenation(padding_chars).value() block_length = self._get_block_length(message + padding) if block_length == initial_block_length + 1: return len(padding) pad_size += 1
def value(self): suffix = [str() for _ in range(self.length)] biased_byte_position = self.BIASED_BYTE_1[0] for i in range(1 + self.length/2): # Generate a prefix long enough to place the ith byte of the # ciphertext in position 15 and the jth byte in position 31. j = i + biased_byte_position + 1 prefix_length = self.length - j + 1 byte_i, byte_j = self._decrypt_bytes(prefix_length) suffix[i] = byte_i if j < self.length: suffix[j] = byte_j return Concatenation(suffix).value()
def _value(self, string): bin_strings = map(self._to_bin, string) return Concatenation(bin_strings).value()
def _compute_value(self): registers = map(self._to_bytes, self.registers) return Concatenation(registers).value()
def rand_bytes(self, count): int_count = int(ceil(count / 4.0)) integers = [self.rand() for _ in range(int_count)] int_bytes = map(lambda integer: IntToBytes(integer).value(), integers) return Concatenation(int_bytes).value()[:count]
def _get_challenge_classes(self): challenge_classes = MatasanoChallenge.__subclasses__() challenge_classes = map(self._get_proper_classes, challenge_classes) return Concatenation(challenge_classes).value()
def expected_value(self): decoded_lines = Base64Decoder().decode_file_lines(self.ANSWER_FILE) return Concatenation(decoded_lines).value()
def value(self): min_length = min(map(len, self.strings)) strings = [string[:min_length] for string in self.strings] return Concatenation(strings).value()
def hash(self, message): hashes = map(lambda function: function().hash(message), self.functions) return Concatenation(hashes).value()
def _build_message_from(self, words): endianness = self.md4.endianness() words = map(lambda word: endianness.from_int(word, 4).value(), words) return Concatenation(words).value()