示例#1
0
文件: tests_3.py 项目: bmcd87/crypto
    def test_challenge_18(self):
        """ Challenge 18: CTR Encryption """

        test = 'L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ=='
        key = "YELLOW SUBMARINE"
        nonce = bytes(8)
        self.assertEqual(b"Yo, VIP Let's kick it Ice, Ice, baby Ice, Ice, baby ", aestools.do_ctr(conv.base_64_to_bytes(test), key, nonce))
        
        roundtrip_input = conv.base_64_to_bytes(aestools.TEXT)
        roundtrip_encrypt = aestools.do_ctr(roundtrip_input, key, nonce)
        self.assertEqual(roundtrip_input, aestools.do_ctr(roundtrip_encrypt, key, nonce))
示例#2
0
文件: tests_3.py 项目: bmcd87/crypto
    def test_challenge_20(self):
        """ Challenge 20: Break fixed-nonce CTR Statistically """

        key = aestools.random_key(16)
        nonce = bytes(8)
        input_file = open('files/20.txt', 'r')
        lines = [conv.base_64_to_bytes(line.rstrip()) for line in input_file]
        input_file.close()
        encrypted_lines = [aestools.do_ctr(line, key, nonce) for line in lines]
        min_length = min([len(line) for line in encrypted_lines])
        concatted = b''.join([line[0:min_length] for line in encrypted_lines])
        test = xortools.breakxor(concatted, min_length)
示例#3
0
文件: tests_3.py 项目: bmcd87/crypto
    def test_challenge_19(self):
        """ Challenge 19: Break fixed-nonce CTR """

        key = aestools.random_key(16)
        nonce = bytes(8)
        input_file = open('files/19.txt', 'r')
        lines = [conv.base_64_to_bytes(line.rstrip()) for line in input_file]
        input_file.close()
        encrypted_lines = [aestools.do_ctr(line, key, nonce) for line in lines]

        index = 0
        probable_bytes = bytearray()
        while(True):
            rotated = "".join([chr(line[index]) if index < len(line) else '' for line in encrypted_lines])
            b, all, score = xortools.solve_xor_block(bytes(rotated, 'utf-8'))
            probable_bytes.append(b)
            index += 1
            if len(rotated) == 0: break

        for line in encrypted_lines:
            close = xortools.xor_bytes(line, bytes(probable_bytes[0 : len(line)]))
            readable = " ".join([chr(b) if b in range(32, 127) else 'X' for b in close])