def inverse(a, n):
    """Find the multiplicative inverse of one number over a given range.

    Adapted from Wikipedia: Extended Euclidian Algorithm -
        http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm

    Returns the multiplicative inverse of a over the finite range n. The result
    is a number which, when multiplied by a, will return 1 over range n.

    Keyword arguments:
    a -- The integer whose multiplicative inverse should be found.
    n -- A positive integer defining the numeric range to evaluate.
    """
    t = 0
    newt = 1
    r = n
    newr = a

    while newr != 0:
        quotient = r // newr
        t, newt = newt, t - quotient * newt
        r, newr = newr, r - quotient * newr

    if r > 1: return None
    if t < 0: t = t + n

    return t