def test_get_all_possible_keys(normal_state: bytes, faulty_state: bytes, key: bytes) -> None: """Assert that key[12], k[9], k[6] and k[3] are in the hypothesis.""" last_key = b"".join(key_expension(key, 11)[-4:]) equations = get_all_possible_keys(_get_state(normal_state), _get_state(faulty_state)) found = False for eq in equations: if all(last_key[i] in eq[i + 1] for i in range(0x10)): found = True assert found
def test_compute_second_column(normal_state: bytes, faulty_state: bytes, key: bytes) -> None: """Assert that key[4], k[1], k[14] and k[11] are in the hypothesis.""" last_key = b"".join(key_expension(key, 11)[-4:]) equations = _compute_second_column(_get_state(normal_state), _get_state(faulty_state)) found = False for d, eq in equations.items(): if last_key[4] in eq[5] and last_key[1] in eq[2] and last_key[ 14] in eq[15] and last_key[11] in eq[12]: found = True assert found
def test_compute_fourth_column(normal_state: bytes, faulty_state: bytes, key: bytes) -> None: """Assert that key[12], k[9], k[6] and k[3] are in the hypothesis.""" last_key = b"".join(key_expension(key, 11)[-4:]) equations = _compute_fourth_column(_get_state(normal_state), _get_state(faulty_state)) found = False for d, eq in equations.items(): if last_key[12] in eq[13] and last_key[9] in eq[10] and last_key[ 6] in eq[7] and last_key[3] in eq[4]: found = True assert found
def test_is_valid_guess(key: bytes, expected: bool) -> None: last_key = b"".join(key_expension(key, 11)[-4:]) normal_state = _get_state(b"\x81\xd6\xcd\xc3\xbd\x16\xfb\x8dr\xb9\xbb\x88\x81\x8b[\xe9") faulty_state = _get_state(b"\xef\xf95\x08c\x01\x87\xb8\xd3IN\x8bp\xe6\x88~") assert _is_valid_guess(normal_state, faulty_state, last_key) == (last_key, expected)