def c2():
    EXAMPLE_INPUT = ( \
        '1c0111001f010100061a024b53535009181c',
        '686974207468652062756c6c277320657965'
        )
    EXAMPLE_OUTPUT = '746865206b696420646f6e277420706c6179'

    plain, key = map(crypto.hex_to_bytes, EXAMPLE_INPUT)
    result = crypto.fixed_xor(plain, key)
    result = crypto.bytes_to_hex(result)

    print(result)
    expect(result, EXAMPLE_OUTPUT)
def c5():
    PLAINTEXT = "Burning 'em, if you ain't quick and nimble\n" + \
        "I go crazy when I hear a cymbal"

    KEY = 'ICE'

    EXAMPLE_OUTPUT = '0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272' + \
        'a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f'


    plain, key = map(crypto.str_to_bytes, (PLAINTEXT, KEY))
    cipher = crypto.fixed_xor(plain, key)
    result = crypto.bytes_to_hex(cipher)

    print(result)
    expect(result, EXAMPLE_OUTPUT)
def c6():
    HAMMING_INPUTS = ('this is a test','wokka wokka!!!')
    distance = textutils.hamming_distance(*map(crypto.str_to_bytes, HAMMING_INPUTS))
    expect(distance, 37)

    with open('inputs/6.txt') as f:
        cipher = f.read()
        cipher = crypto.base64_to_bytes(cipher)
        
        keysize = crypto.brute_xor_keysize(cipher)
        print('Guessing the key size is {0}'.format(keysize))

        key = crypto.brute_xor_key(cipher, keysize)
        print('Key: {0}'.format(key))

        plain = crypto.fixed_xor(cipher, crypto.str_to_bytes(key))
        print ('Plain: {0}'.format(plain.decode('utf-8')))