예제 #1
0
def sol_count(a, b, m):
    """
    Returns number of solutions of ax ≡ b (mod m) that are least residue (mod m)

    Parameters
    ----------
    a : int
        denotes a in ax ≡ b (mod m)
    b : int
        denotes b in ax ≡ b (mod m)
    m : int
        denotes m in ax ≡ b (mod m)

    """
    if (isSol(a, b, m) == False):
        return 0
    elif (isCoprime(a, m)):
        return 1
    else:
        return gcd(a, m)
예제 #2
0
def fermat_prime_checker(p, a):
    """
    Checks if p is prime using fermat's principle
    If p is prime and gcd(a, p) = 1, then a^(p-1) ≡ 1 (mod p)

    Parameters
    ----------
    p : int
        denotes a natural number that has to be checked for prime
    a : int
        denotes a natural number co-prime with p
    return : bool
        return true if p is prime otherwise false

    """
    if (isCoprime(a, p) == False):
        raise ValueError("a must be co-prime with p")

    if (p == 1):
        return False
    return (math.pow(a, p - 1) % p) == (1 % p)
예제 #3
0
def order(a, m):
    """
    Returns order of a modulo m 
    order of a modulo m is the smallest positive integer t such that a^t ≡ 1 (mod m)

    Parameters
    ----------
    a : int
        denotes positive integer a in a^t ≡ 1 (mod m)
    m : int
        denotes positive integer m in a^t ≡ 1 (mod m)
    return : int
        returns least integet t such that a^t ≡ 1 (mod m)

    """
    if (isCoprime(a, m) == False):
        raise ValueError("a and m must be co-prime")
    i = 1
    while True:
        if (((math.pow(a, i)) % m) == 1):
            break
        i = i + 1
    return i
예제 #4
0
def test_isCoprime2():
    a = 100
    b = 77895345
    assert isCoprime(a, b) == False
예제 #5
0
def test_isCoprime1():
    a = 343
    b = 10000
    assert isCoprime(a, b) == True