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 challenge_3(): hex_string = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736" cipher_bytes = crypto.hex_to_bytes(hex_string) candidate_bytes = [[byte] for byte in range(0, 255)] result = crypto.brute_single_xor(cipher_bytes, candidate_bytes) print("Plaintext: %s" % result[1])
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))
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)
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)
def challenge_4(): input_file = "1-4.txt" candidate_bytes = [[byte] for byte in range(0, 255)] best_result = (None, None, 0) for line in open(input_file).readlines(): line = line.strip() if not line: continue cipher_bytes = crypto.hex_to_bytes(line) result = crypto.brute_single_xor(cipher_bytes, candidate_bytes) if result[1] and result[2] > best_result[2]: best_result = result print("Plaintext: %s" % best_result[1])