Esempio n. 1
0
 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
Esempio n. 2
0
 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()
Esempio n. 3
0
 def _value(self, string):
     bin_strings = map(self._to_bin, string)
     return Concatenation(bin_strings).value()
Esempio n. 4
0
 def _compute_value(self):
     registers = map(self._to_bytes, self.registers)
     return Concatenation(registers).value()
Esempio n. 5
0
 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]
Esempio n. 6
0
File: run.py Progetto: lukius/mts
 def _get_challenge_classes(self):
     challenge_classes = MatasanoChallenge.__subclasses__()
     challenge_classes = map(self._get_proper_classes, challenge_classes)
     return Concatenation(challenge_classes).value()
Esempio n. 7
0
 def expected_value(self):
     decoded_lines = Base64Decoder().decode_file_lines(self.ANSWER_FILE)
     return Concatenation(decoded_lines).value()
Esempio n. 8
0
 def value(self):
     min_length = min(map(len, self.strings))
     strings = [string[:min_length] for string in self.strings]
     return Concatenation(strings).value()
Esempio n. 9
0
 def hash(self, message):
     hashes = map(lambda function: function().hash(message), self.functions)
     return Concatenation(hashes).value()
Esempio n. 10
0
File: md4.py Progetto: lukius/mts
 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()