Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

modlog

Modular (or: Discrete) Logarithm


Description

Realizes the modular (or discrete) logarithm modulo a prime number p, that is determines the unique exponent n such that g^n = x \, \mathrm{mod} \, p, g a primitive root.

Usage

modlog(g, x, p)

Arguments

g

a primitive root mod p.

x

an integer.

p

prime number.

Details

The method is in principle a complete search, cut short by "Shank's trick", the giantstep-babystep approach, see Forster (1996, pp. 65f). g has to be a primitive root modulo p, otherwise exponentiation is not bijective.

Value

Returns an integer.

References

Forster, O. (1996). Algorithmische Zahlentheorie. Friedr. Vieweg u. Sohn Verlagsgesellschaft mbH, Wiesbaden.

See Also

Examples

modlog(11, 998, 1009)  # 505 , i.e., 11^505 = 998 mod 1009

numbers

Number-Theoretic Functions

v0.8-1
GPL (>= 3)
Authors
Hans Werner Borchers
Initial release
2021-04-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.