Beispiel #1
0
def c3():
    INPUT = ('1b37373331363f78151b7f2b783431333d' +
             '78397828372d363c78373e783a393b3736')
    inputbytes = crypto.hex_to_bytes(INPUT)
    keyrange = [[byte] for byte in range(0, 255)]
    keybytes, text = crypto.brute_xor(inputbytes, keyrange)
    print('Decoded text: %r' % text)
Beispiel #2
0
def c3():
    INPUT = ('1b37373331363f78151b7f2b783431333d' +
             '78397828372d363c78373e783a393b3736')
    inputbytes = crypto.hex_to_bytes(INPUT)
    keyrange = [[byte] for byte in range(0, 255)]
    keybytes, text = crypto.brute_xor(inputbytes, keyrange)
    print('Decoded text: %r' % text)
def c3():
    EXAMPLE_INPUT = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'

    ciphertext = crypto.hex_to_bytes(EXAMPLE_INPUT)
    potential_keys = [[b] for b in range(0, 255)]

    key, plain = crypto.brute_xor(ciphertext, potential_keys)
    print('Key: {0}'.format(key))
    print('Plaintext: {0}'.format(plain))
Beispiel #4
0
def c6():
    b64text = open('inputs/6.txt').read()
    cipherbytes = crypto.base64_to_bytes(b64text)
    keysizes = crypto.brute_keysize(cipherbytes)
    keyrange = [[byte] for byte in range(0, 255)]
    # Identify key candidates by trying single byte keys, spaced keysize
    # bytes apart.
    key_candidates = []
    for keysize in keysizes:
        chunks = crypto.split_every_n_bytes(cipherbytes, keysize)
        key = b''
        for chunk in chunks:
            k, text = crypto.brute_xor(chunk, keyrange)
            key += bytes(k)
        key_candidates.append(key)
    # Now run the key candidates and find the winner.
    key, text = crypto.brute_xor(cipherbytes, key_candidates)
    print('Decrypted with key: %s' % key.decode())
    print('%s' % text)
Beispiel #5
0
def c6():
    b64text = open('inputs/6.txt').read()
    cipherbytes = crypto.base64_to_bytes(b64text)
    keysizes = crypto.brute_keysize(cipherbytes)
    keyrange = [[byte] for byte in range(0, 255)]
    # Identify key candidates by trying single byte keys, spaced keysize
    # bytes apart.
    key_candidates = []
    for keysize in keysizes:
        chunks = crypto.split_every_n_bytes(cipherbytes, keysize)
        key = b''
        for chunk in chunks:
            k, text = crypto.brute_xor(chunk, keyrange)
            key += bytes(k)
        key_candidates.append(key)
    # Now run the key candidates and find the winner.
    key, text = crypto.brute_xor(cipherbytes, key_candidates)
    print('Decrypted with key: %s' % key.decode())
    print('%s' % text)
def c4():
    texts = []
    keys = [[b] for b in range(0, 255)]
    for line in open('inputs/4.txt').readlines():
        line = line.strip()
        _, text = crypto.brute_xor(crypto.hex_to_bytes(line), keys)
        if text:
            texts.append(text)
    best = max(texts, key=textutils.probability_english)

    print(best)
Beispiel #7
0
def c4():
    texts = []
    keyrange = [[byte] for byte in range(0, 255)]
    for line in open('inputs/4.txt').readlines():
        line = line.strip()
        if not line:
            continue
        key, text = crypto.brute_xor(crypto.hex_to_bytes(line), keyrange)
        if text: texts.append(text)
    best_text = max(texts, key=textutil.english_probability)
    print('Decoded text: %r' % best_text)
Beispiel #8
0
def c4():
    texts = []
    keyrange = [[byte] for byte in range(0, 255)]
    for line in open('inputs/4.txt').readlines():
        line = line.strip()
        if not line:
            continue
        key, text = crypto.brute_xor(crypto.hex_to_bytes(line), keyrange)
        if text: texts.append(text)
    best_text = max(texts, key=textutil.english_probability)
    print('Decoded text: %r' % best_text)