def METHOD_NAME(q: BNP12, p: BNP12) -> BNF12:
    """
    The core of the pairing algorithm.
    """
    if p == BNP12.point_at_infinity() or q == BNP12.point_at_infinity():
        return BNF12.from_int(1)
    r = q
    f = BNF12.from_int(1)
    for i in range(ATE_PAIRING_COUNT_BITS, -1, -1):
        f = f * f * linefunc(r, r, p)
        r = r.double()
        if (ATE_PAIRING_COUNT - 1) & (2**i):
            f = f * linefunc(r, q, p)
            r = r + q
    assert r == q.mul_by(ATE_PAIRING_COUNT - 1)
    q1 = BNP12(q.x.frobenius(), q.y.frobenius())
    nq2 = BNP12(q1.x.frobenius(), -q1.y.frobenius())
    f = f * linefunc(r, q1, p)
    r = r + q1
    f = f * linefunc(r, nq2, p)
    return f ** ((ALT_BN128_PRIME**12 - 1) // ALT_BN128_CURVE_ORDER)