def modular_pow(base, exponent, modulus):
    """Use modular exponentiation to calculate number to high powers.

    Adapted from Wikipedia: Modular exponentiation -
        http://en.wikipedia.org/wiki/Modular_exponentiation

    Returns the result of raising an integer to a high power over a given
    modulus. Rather than calculate the full power and divide the resulting
    number by the modulus, this algorithm applies the modulus to a running
    value multiplied by the base integer a number of times, determined by the
    exponent.

    Keyword arguments:
    base -- An integer to be raised to a desired power, modulo a given modulus.
    exponent -- An integer power to which to raise the base.
    modulus -- An integer modulus to apply to the result of the power operation.
    """
    c = 1

    for e_prime in range(exponent):
        c = (c * base) % modulus

    return c