Example #1
0
def detect_repeat(raw):
    blocksize = 16
    tests = {}
    for i in range(0, len(raw) // blocksize):
        subblock = raw[i * blocksize:(i + 1) * blocksize]
        string = conv.bytes_to_hex(subblock)
        if string in tests:
            return True
        tests[string] = True

    return False
Example #2
0
    def test_challenge_5(self):
        """ Challenge 5: Implement repeating key XOR """

        input = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal"
        input_bytes = input.encode("utf-8")
        key = "ICE"
        key_bytes = key.encode("utf-8")

        expected_output = "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f"
        hex_output = conv.bytes_to_hex(xortools.xor_repeating(input_bytes, key_bytes))
        self.assertEqual(hex_output, expected_output)