Example #1
0
    def test_challenge_2(self):
        """ Challenge 2: XOR two strings """

        input_one = '1c0111001f010100061a024b53535009181c'
        input_two = '686974207468652062756c6c277320657965'
        expected_out = '746865206b696420646f6e277420706c6179'

        bytes_one = conv.hex_to_bytes(input_one)
        bytes_two = conv.hex_to_bytes(input_two)
        expected_bytes_out = conv.hex_to_bytes(expected_out)

        self.assertEqual(xortools.xor_bytes(bytes_one, bytes_two), expected_bytes_out)
Example #2
0
    def test_challenge_3(self):
        """ Challenge 3: Find xor cipher byte """

        input = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
        input_bytes = conv.hex_to_bytes(input)

        b, output, score = xortools.solve_xor_block(input_bytes)
        self.assertEqual(b, 88)
        self.assertEqual(output, b"Cooking MC's like a pound of bacon")
Example #3
0
def find_xored_bytes(file):
    current_score = 0
    current_encrypted = bytes()
    current_decrypted = bytes()
    for line in file:
        input = conv.hex_to_bytes(line.rstrip())
        (b, output, score) = solve_xor_block(input)
        if current_score == 0 or score < current_score:
            current_score = score 
            current_encrypted = input
            current_decrypted = output
    return (current_encrypted, current_decrypted)
Example #4
0
def find_aes(file):
    for line in file:
        line = line.rstrip()
        raw = conv.hex_to_bytes(line)
        if detect_repeat(raw):
            return line