Example #1
0
def _factor_order(m, u, era=None):
    """
    Return triple (k, q, primes) if m is factored as m = kq,
    where k > 1 and q is a probable prime > u.
    u is expected to be (n^(1/4)+1)^2 for Atkin-Morain ECPP.
    If m is not successfully factored into desired form,
    return (False, False, primes).
    The third component of both cases is a list of primes
    to do trial division.

    Algorithm 27 (Atkin-morain ECPP) Step3
    """
    if era is None:
        v = min(500000, int(log(m)))
        era = factor.mpqs.eratosthenes(v)
    k = 1
    q = m
    for p in era:
        if p > u:
            break
        e, q = arith1.vp(q, p)
        k *= p**e
    if q < u or k == 1:
        return False, False, era
    if not prime.millerRabin(q):
        return False, False, era
    return k, q, era
Example #2
0
def factor_orders(m, n):
    """
    m = kq
    Args:
        m: for factorizations
        n: the integer for prime proving. Used to compute bound

    Returns:

    """
    k = 1
    q = m
    bound = (floorpowerroot(n, 4) + 1) ** 2
    for p in small_primes:
        '''
        Check again.
        '''
        # if q becomes too small, fails anyway
        if q <= bound:
            break
        # if p is over the bound, and p is a factor of q. A solution is found.
        if p > bound and q % p == 0:
            k *= q/p
            q = p
            break
        # When q is > bound. Try to factorize through small primes.
        while q % p == 0:
            q = q/p
            k *= p

    if q <= bound or k == 1:
        return None
    if not prime.millerRabin(q):
        return None
    return k, q
Example #3
0
def _factor_order(m, u, era=None):
    """
    Return triple (k, q, primes) if m is factored as m = kq,
    where k > 1 and q is a probable prime > u.
    u is expected to be (n^(1/4)+1)^2 for Atkin-Morain ECPP.
    If m is not successfully factored into desired form,
    return (False, False, primes).
    The third component of both cases is a list of primes
    to do trial division.

    Algorithm 27 (Atkin-morain ECPP) Step3
    """
    if era is None:
        v = min(500000, int(log(m)))
        era = factor.mpqs.eratosthenes(v)
    k = 1
    q = m
    for p in era:
        if p > u:
            break
        e, q = arith1.vp(q, p)
        k *= p ** e
    if q < u or k == 1:
        return False, False, era
    if not prime.millerRabin(q):
        return False, False, era
    return k, q, era