"""8. Detect AES in ECB mode."""
from typing import Iterator, Optional

import lib.analysis as analysis


def find_aes_ecb_ct(cts: Iterator[bytes]) -> Optional[bytes]:
    return next(filter(analysis.is_aes_ecb_ct, cts), None)


def test_solution() -> None:
    with open("data/08.txt") as f:
        cts = (bytes.fromhex(line) for line in f)
        got = find_aes_ecb_ct(cts)
    want = "<KEY>"
    if got is None:
        raise RuntimeError("no AES-ECB ciphertext found")
    assert want == got.hex()
