def message5_5_gp1(state):
    # (p-1) is essentially (-1)
    # B's secret is (-1)^b which is either (+1) or (-1) (and also B)
    # A's secret is (-1)^b^a, which is either (+1) or (-1),
    # but not necessarily the same as B's secret
    # thus, we may need to modify cipher
    # use CBC padding to check validity of key
    # check validity of cbc padding to determine which
    # B's secret 
    cipherkey_plus1, mackey_plus1 = secretToKeys(intToBytes(1));
    cipherkey_minus1, mackey_minus1 = secretToKeys(intToBytes(1-state["p"]));
    plain_plus1 = aes_cbc_dec(state["a_cipher"], cipherkey_plus1, state["a_iv"])
    plain_minus1 = aes_cbc_dec(state["a_cipher"], cipherkey_minus1, state["a_iv"])
    plain = None;
    try:
        plain = checkAndRemovePKCS7Padding(plain_plus1)
        state["m_key_a"] = cipherkey_plus1
    except ValueError:
        plain = checkAndRemovePKCS7Padding(plain_minus1)
        state["m_key_a"] = cipherkey_minus1
    state["m_plain_a"] = plain;
    # encrypt to B's key
    state["m_key_b"], b_mackey = secretToKeys(intToBytes(state["B"]))
    state["a_cipher"] = aes_cbc_enc(addPKCS7Padding(plain, 16), state["m_key_b"], state["a_iv"]);
    return state;
dataset/ETHPy150Open reschly/cryptopals/prob35.py/message5_5_gp1/swapped operands of `-`