gives ab mod m.
finds the modular inverse of a modulo m.
finds a modular r root of a.
- PowerMod is also known as modular exponentiation.
- Mathematical function, suitable for both symbolic and numerical manipulation.
- Typically used in modular arithmetic, cryptography, random number generation and cyclic operations in programs.
- PowerMod[a,b,m] gives the remainder of ab divided by m.
- PowerMod[a,b,m] allows negative and rational values of b. It returns unevaluated if the corresponding modular inverse or root does not exist.
- For positive b, PowerMod[a,b,m] gives the same result as Mod[a^b, m] but is much more efficient.
Examplesopen allclose all
Basic Examples (3)
Numerical Manipulation (4)
PowerMod threads over lists:
Symbolic Manipulation (3)
Use Reduce to simplify expressions:
Use FindInstance to find solutions to expressions containing PowerMod
Use PowerMod in a sum:
Basic Applications (2)
Find a PrimitiveRoot of 9:
Use PowerMod to generate all coprime integers modulo 9:
Find all base 2 pseudoprimes below 1000:
Number Theory (4)
Build an RSA-like toy encryption scheme. Start with the modulus:
Find the universal exponent of the multiplication group modulo n:
Build an RSA-like toy encryption scheme:
Perform a cycling attack. One of the outputs will be the plaintext:
Alice and Bob publicly agree on a prime number and a primitive root modulo that prime :
Then Alice and Bob each choose private keys:
Then Alice sends Bob mod while Bob sends Alice mod :
Bob then computes mod and Alice computes mod :
This is their secret number which they now both share:
Create a random number generator that uses the current time as a seed:
Properties & Relations (8)
PowerMod is a periodic function:
Fermat's little theorem states that when is prime, then :
Neat Examples (3)
Plot a list of powers of 3 where the exponent is varied, modulo some prime number:
Plot values of varying powers of numbers with a fixed modulus:
Plot an Ulam spiral where numbers are colored based on PowerMod:
Wolfram Research (1988), PowerMod, Wolfram Language function, https://reference.wolfram.com/language/ref/PowerMod.html.
Wolfram Language. 1988. "PowerMod." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PowerMod.html.
Wolfram Language. (1988). PowerMod. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PowerMod.html