py_ecc/bls/utils.py
def modular_squareroot_in_FQ2(value: FQ2) -> FQ2:
    """
    ``modular_squareroot_in_FQ2(x)`` returns the value ``y`` such that ``y**2 % q == x``,
    and None if this is not possible. In cases where there are two solutions,
    the value with higher imaginary component is favored;
    if both solutions have equal imaginary component the value with higher real
    component is favored.
    """
    candidate_squareroot = value ** ((FQ2_order + 8) // 16)
    check = candidate_squareroot ** 2 / value
    if check in eighth_roots_of_unity[::2]:
        x1 = candidate_squareroot / eighth_roots_of_unity[eighth_roots_of_unity.index(check) // 2]
        x2 = -x1
        x1_re, x1_im = x1.coeffs
        x2_re, x2_im = x2.coeffs
        return x1 if (x1_im > x2_im or (x1_im == x2_im and x1_re > x2_re)) else x2
    return None
def modular_squareroot_in_FQ2(value: FQ2) -> FQ2:
    """
    ``modular_squareroot_in_FQ2(x)`` returns the value ``y`` such that ``y**2 % q == x``,
    and None if this is not possible. In cases where there are two solutions,
    the value with higher imaginary component is favored;
    if both solutions have equal imaginary component the value with higher real
    component is favored.
    """
    candidate_squareroot = value ** ((FQ2_order + 8) // 16)
    check = candidate_squareroot ** 2 / value
    if check in eighth_roots_of_unity[::2]:
        x1 = candidate_squareroot / eighth_roots_of_unity[eighth_roots_of_unity.index(check) // 2]
        x2 = -x1
        x1_re, x1_im = x1.coeffs
        x2_re, x2_im = x2.coeffs
        return x1 if (x1_im > x2_im or (x1_im == x2_im and x1_re > x2_re)) else x2
    return None
def modular_squareroot_in_FQ2 ( value : FQ2 ) -> FQ2 : candidate_squareroot = value ** ( ( FQ2_order + 8 ) // 16 ) check = candidate_squareroot ** 2 / value if check in eighth_roots_of_unity [ : : 2 ] : x1 = candidate_squareroot / eighth_roots_of_unity [ eighth_roots_of_unity . index ( check ) // 2 ] x2 = - x1 x1_re , x1_im = x1 . coeffs x2_re , x2_im = x2 . coeffs return x1 if ( x1_im > x2_im or ( x1_im == x2_im and x1_re > x2_re ) ) else x2 return None
``modular_squareroot_in_FQ2(x)`` returns the value ``y`` such that ``y**2 % q == x``,
    and None if this is not possible. In cases where there are two solutions,
    the value with higher imaginary component is favored;
    if both solutions have equal imaginary component the value with higher real
    component is favored.
modular_squareroot_in_FQ2 ( x ) returns the value y such that y ** 2 % q == x and None if this is not possible . In cases where there are two solutions the value with higher imaginary component is favored ; if both solutions have equal imaginary component the value with higher real component is favored .