def test_break_repeating_key_xor_2(): test = "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f" ciphertext_bytes = binascii.unhexlify(test) plaintexts = [ decrypt[2] for decrypt in set1.break_repeating_key_xor(ciphertext_bytes) ] assert "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal" in plaintexts, \ "Plaintext should be decrypted by break_repeating_key_xor()"
def break_repeating_nonce_ctr(ciphertexts): """ Decrypt CTR encrypted ciphertexts that were encrypted with a fixed nonce :param ciphertextx: A list of ciphertexts encrypted with a fixed nonce :return: A list of decrypted plaintexts """ block_size = 16 ciphertext = ''.join(ct[:block_size] for ct in ciphertexts) guess = list(chunks(break_repeating_key_xor(ciphertext, keysize=block_size), block_size)) block_keystream = string_xor(guess[0], ciphertexts[0]) plaintexts = [] for ct in ciphertexts: plaintext = '' for block in chunks(ct, block_size): plaintext += string_xor(block, block_keystream) plaintexts.append(plaintext) return plaintexts
def test_break_repeating_key_xor_1(): pt = b'The libel pleaded that the pew was erected under a faculty in 1725, and was transferred to Haines in 1816.' key = b'\x30\x30\xff' test = set1.repeating_key_xor(pt, key) plaintexts = [decrypt[2] for decrypt in set1.break_repeating_key_xor(test)] assert pt in plaintexts, "Plaintext should be decrypted by break_repeating_key_xor()"
def test_break_repeating_key_xor(self): with open('6.txt') as f: contents = bytes(base64.b64decode(f.read())) deciphered, key, error = set1.break_repeating_key_xor(contents) self.assertIn(b"I'm back and I'm ringin' the bell \nA rockin'", deciphered)
def test_break_repeating_key_xor(): """ Set 1, Challenge 6 """ assert (set1.break_repeating_key_xor(open(SCRIPT_DIR + 'test_data/1_6.txt', 'r').read().decode('base64'))[:83] == "I'm back and I'm ringin' the bell \nA rockin' on the mike while the fly girls yell \n")
def test_break_repeating_key_xor_2(): test = "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f" ciphertext_bytes = binascii.unhexlify(test) plaintexts = [decrypt[2] for decrypt in set1.break_repeating_key_xor(ciphertext_bytes)] assert "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal" in plaintexts, \ "Plaintext should be decrypted by break_repeating_key_xor()"