Discrete Logarithms and Primitive Roots Algorithms
Discrete Logarithms and Primitive Roots Algorithms
DOI: 10.54254/2753-8818/13/20240801
Junchi Yang
University of Waterloo, Ontario, Waterloo, Canada
j647yang@uwaterloo.ca
Abstract. In mathematics, the logarithm, log 𝑎 𝑏, where a∈ (0,1) ∪ (1, ∞) and b>0, is always
defined as the real number x, such that 𝑎 𝑥 =b. Moreover, in the field of number theory, a similar
concept called the discrete logarithm can be defined as follows: For a given positive integer
m(m≥ 2), let a∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1 , and r is the primitive root of m, x=𝑖𝑛𝑑𝑟 𝑎 if 𝑟 𝑥 ≡
𝑎 (𝑚𝑜𝑑 𝑚) . Here, x is the discrete logarithm. The Discrete Logarithm Problem, which is a
famous problem in number theory, is formulized as: For a positive integer b and a prime number
p, and a is the primitive root of p, the goal is to find the exact value of i, such that 𝑎𝑖 ≡
𝑏 (𝑚𝑜𝑑 𝑝), in other words, it is targeted at finding the exact value of 𝑖𝑛𝑑𝑎 𝑏. The goal of this
research is to give several solutions to the Discrete Logarithm Problem, so firstly, some
background concept like order and primitive root will be introduced with the proof of some
foundational theories of these two concepts, then this essay will give two methods that can solve
the Discrete Logarithm Problem called Shanks' Babystep-Giantstep Algorithm and Pohlig-
Hellman Discrete Logarithm Algorithm.
Keywords: Discrete Logarithm, The Discrete Logarithm Problem, Order, Primitive Root.
1. Introduction
In cryptographic circles, the discrete logarithm remains a topic of intrigue. Although the discrete
logarithm can be computed in specific scenarios, finding efficient solutions for general cases remains a
formidable challenge. Notably, some algorithms tackle this problem and hold paramount significance in
public-key cryptography, exemplified by systems like Elgamal [1]. This research endeavors to illuminate
the intricacies of the Shanks' Babystep-Giantstep Algorithm and the Pohlig-Hellman Discrete Logarithm
Algorithm. Both stand as robust solutions to the Discrete Logarithm Problem. To lay a foundation, it's
imperative first to delve into fundamental concepts such as order and primitive root. By understanding
these, one can better appreciate their applications to the focal problem. The crux of this study revolves
around the operational mechanics of these two algorithms, exploring their methodologies in solving the
Discrete Logarithm Problem, and discerning their connections to foundational tenets of elementary
number theory.
© 2023 The Authors. This is an open access article distributed under the terms of the Creative Commons Attribution License 4.0
(https://creativecommons.org/licenses/by/4.0/).
95
Proceedings of the 3rd International Conference on Computing Innovation and Applied Physics
DOI: 10.54254/2753-8818/13/20240801
2.1. Order
Definition 1: Let 𝑚 ∈ 𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1, the order (or the multiplicative order) of a
modulo m is the smallest positive integer r satisfying 𝑎𝑟 ≡ 1 (𝑚𝑜𝑑 𝑚) [2].
The order of a modulo m is always written as 𝛿𝑚 (𝑎) or 𝑜𝑟𝑑𝑚 (𝑎) [3]. Also, order always exists due
to the Euler’s Theorem: Let 𝑚 ∈ 𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1 , then 𝑎𝜑(𝑚) ≡ 1 (𝑚𝑜𝑑 𝑚) [4].
Euler’s Theorem is too basic so the proof is skipped here. The Euler’s Theorem says that for 𝑚 ∈
𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1, the set {r∈ 𝑁 + | 𝑎𝑟 ≡ 1(𝑚𝑜𝑑 𝑚)} is not empty so this set must have
the smallest element, which is the (multiplicative) order, due to the Well-Ordering Principle.
Proposition 1: Let 𝑚 ∈ 𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1, 𝑘 ∈ 𝑁 + , then 𝑎𝑘 ≡ 1 (𝑚𝑜𝑑 𝑚) if and
only if 𝛿𝑚 (𝑎) | 𝑘 [5].
Proof: If 𝑎𝑘 ≡ 1(𝑚𝑜𝑑 𝑚), let, then 𝑎𝑟 ≡ 1 (𝑚𝑜𝑑 𝑚).
By Division Algorithm, there exists q, t∈ 𝑁 + with 0≤ 𝑡<r-1 such that k=qr+t.
This means t=k-qr.
Also, notice that 𝑎𝑞𝑟 ≡ 1 (𝑚𝑜𝑑𝑚).
Thus, 𝑎𝑡 = 𝑎𝑘−𝑞𝑟 ≡ 𝑎𝑘−𝑞𝑟 𝑎𝑞𝑟 = 𝑎𝑘 ≡ 1(𝑚𝑜𝑑𝑚).
But r is the smallest positive integer satisfying 𝑎𝑟 ≡ 1 (𝑚𝑜𝑑 𝑚) and t<r, so it means t=0
So k=qr, which means r|k.
Therefore, 𝛿𝑚 (a)|k.
On the other hand, if 𝛿𝑚 (𝑎) | 𝑘, so r |k, thus there exists 𝑙 ∈ 𝑁 + , such that k= lr.
Since 𝑎𝑟 ≡ 1 (𝑚𝑜𝑑 𝑚), thus, 𝑎𝑘 = 𝑎𝑙𝑟 = (𝑎𝑟 )𝑙 ≡ 1 (𝑚𝑜𝑑 𝑚).
Hence, 𝑎𝑘 ≡ 1 (𝑚𝑜𝑑 𝑚) if and only if 𝛿𝑚 (𝑎) | 𝑘.
By Proposition1 and Euler’s Theorem, a result can be got easily:
Corollary 1: Let 𝑚 ∈ 𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1, then 𝛿𝑚 (𝑎) | 𝜑(𝑚).
Proof: By Euler’s Theorem, 𝑎𝜑(𝑚) ≡ 1 (𝑚𝑜𝑑 𝑚).
By Proposition1 and let k= 𝜑(𝑚), 𝛿𝑚 (𝑎) | 𝜑(𝑚).
So the Corollary1 holds.
Next, another important result about (multiplicative) order will be introduced.
Proposition 2: Let 𝑚 ∈ 𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1, then a, 𝑎2 , … , 𝑎𝑟 are distinct modulo m,
where r= 𝛿𝑚 (a) [6].
Proof: Suppose ∃1 ≤ 𝑖 < 𝑗 ≤ 𝑟, 𝑠. 𝑡. 𝑎𝑖 ≡ 𝑎 𝑗 (𝑚𝑜𝑑 𝑚), 𝑡ℎ𝑒𝑛 𝑎𝑖 (𝑎 𝑗−𝑖 − 1) ≡ 0(𝑚𝑜𝑑 𝑚).
This means m | 𝑎𝑖 (𝑎 𝑗−𝑖 − 1).
Since (a, m) =1, so (𝑎𝑖 , m) =1.
Thus, m | 𝑎 𝑗−𝑖 − 1, which means 𝑎 𝑗−𝑖 ≡ 1(𝑚𝑜𝑑 𝑚).
Hence, r | j-i, so j-i ≥ 𝑟.
But 1 ≤ 𝑖 < 𝑗 ≤ 𝑟, which says j-i<r, it is a contradiction.
Hence, a, 𝑎2 , … , 𝑎𝑟 are distinct modulo m.
𝑟
Proposition 2: Let 𝑚 ∈ 𝑁 + , 𝑎𝑛𝑑 𝑎 ∈ 𝑁 + 𝑤𝑖𝑡ℎ (𝑎, 𝑚) = 1, let 𝛿𝑚 (a) = r, then 𝛿𝑚 (𝑎𝑛 ) =(𝑟,𝑛) (𝑛 ∈
𝑁 + ) [7].
Proof: Let 𝛿𝑚 (𝑎𝑛 )= 𝑙, then 𝑎𝑛𝑙 ≡ 1(𝑚𝑜𝑑 𝑚).
By Proposition1, r | 𝑙n, so ∃ 𝑞 ∈ 𝑁 + , 𝑠. 𝑡. 𝑛𝑙 = 𝑟𝑞
𝑙𝑛 𝑟
Thus, (𝑟,𝑛) = (𝑟,𝑛) 𝑞.
𝑟 𝑙𝑛
So (𝑟,𝑛)
| (𝑟,𝑛)
.
𝑟 𝑛
Notice that ((𝑟,𝑛) , (𝑟,𝑛)
) = 1.
𝑟 𝑙 𝑟
Hence, (𝑟,𝑛)
| (𝑟,𝑛)
., so (𝑟,𝑛) | 𝑙.
𝑟 𝑛
On the other hand, notice that (𝑎𝑛 )(𝑟,𝑛) = (𝑎𝑟 )(𝑟,𝑛) ≡ 1(𝑚𝑜𝑑 𝑚).
96
Proceedings of the 3rd International Conference on Computing Innovation and Applied Physics
DOI: 10.54254/2753-8818/13/20240801
𝑟
By Proposition1, 𝑙| (𝑟,𝑛)
.
𝑟
Therefore, 𝑙 = (𝑟,𝑛) .
𝑟
Hence, 𝛿𝑚 (𝑎𝑛 )=(𝑟,𝑛) .
97
Proceedings of the 3rd International Conference on Computing Innovation and Applied Physics
DOI: 10.54254/2753-8818/13/20240801
𝑑 𝑑
By Lemma, 𝛿𝑝 (𝑏) = 𝛿𝑝 (𝑎𝑞 𝑐 𝑙1 ) = 𝛿𝑝 (𝑎𝑞 ) 𝛿𝑝 (𝑐 𝑙1 ) = 𝑘1 𝑞𝑒 > 𝑞 𝑑 𝑘1 = 𝑘 = 𝛿𝑝 (𝑎).
Thus, an element b in 𝑍𝑝∗ with greater order than a is found.
Following this way, new elements in 𝑍𝑝∗ with strictly increasing order can be found until find an
element with the order p-1 and that element is just the primitive root.
In general, 𝑍𝑝∗ has a primitive root.
The Primitive Root Theorem tells that every prime number has its own primitive root but there are
still many problems about primitive root cannot be solved by this theorem although it has already been
an amazing result. Also, the Primitive Root Theorem can describe why the assumption of Discrete
Logarithm Problem always holds and this point will be discussed in the following session of this essay.
The following is to introduce several results of primitive roots without proof since it does not have a
close relation to the main topic of this research.
Theorem 2: Let m∈ 𝑁 + (𝑚 ≥ 2). If 𝑍𝑚 ∗
has primitive roots, then the number of primitive roots in
∗
𝑍𝑚 is 𝜑(𝜑(𝑚)) [8].
In particular, if m = p is a prime number, then 𝜑(𝜑(𝑚)) = 𝜑(𝑝 − 1), so it can tell that for any prime
number p, the total number of primitive roots of p is 𝜑(𝑝 − 1).
Theorem 3: Let m ∈ 𝑁 + (𝑚 ≥ 2) . Then 𝑍𝑚 ∗
has primitive roots if and only if m ∈
𝑘 𝑘 +
{2,4, 𝑝 ,2𝑝 | 𝑝 𝑖𝑠 𝑎𝑛 𝑜𝑑𝑑 𝑝𝑟𝑖𝑚𝑒 𝑎𝑛𝑑 𝑘 ∈ 𝑁 } [9].
This result tells the structure of m that has primitive roots of m.
98
Proceedings of the 3rd International Conference on Computing Innovation and Applied Physics
DOI: 10.54254/2753-8818/13/20240801
99
Proceedings of the 3rd International Conference on Computing Innovation and Applied Physics
DOI: 10.54254/2753-8818/13/20240801
This system of congruences has an unique solution modulo 𝑚1 𝑚2 … 𝑚𝑘 . In other words, if 𝑥 =𝑥0
is a particular solution of this system, then all the solutions are given by all the integers
𝑥 𝑠𝑎𝑡𝑖𝑠𝑓𝑦𝑖𝑛𝑔 𝑥 ≡ 𝑥0 (𝑚𝑜𝑑 𝑚1 𝑚2 … 𝑚𝑘 ) [7].
This theorem is a very basic result in number theory so the proof does not present in this essay but
the proof can tell the algorithm to solve the system of congruences by using Chinese Remainder
Theorem.
The solutions can be given by the formula:
𝑥 ≡ 𝑎1 𝑀1 𝑦1 + 𝑎2 𝑀2 𝑦2 + ⋯ + 𝑎𝑛 𝑀𝑛 𝑦𝑛 (mod 𝑚1 𝑚2 … 𝑚𝑘 ) (2)
𝑀
Where, 𝑀𝑖 = 𝑚𝑖
, 𝑀 = 𝑚1 𝑚2 … 𝑚𝑘 , 𝑦𝑖 = (𝑀𝑖 )−1 (𝑚𝑜𝑑 𝑚𝑖 ) , 𝑖 = 1,2, … , 𝑘.
Now, it is the time to present the Pohlig-Hellman Discrete Logarithm Algorithm [11]:
Algorithm 2(Pohlig-Hellman Discrete Logarithm Algorithm):
Consider the prime factorization of p-1 = 𝑝1 𝑘1 𝑝2 𝑘2 … 𝑝𝑚 𝑘𝑚 ;
For each prime factor 𝑝𝑖 (1 ≤ 𝑖 ≤ 𝑚), let x = 𝑎0 + 𝑎1 𝑝𝑖 + ⋯ + 𝑎𝑘𝑖−1 𝑝𝑖 𝑘𝑖−1 (𝑚𝑜𝑑 𝑝𝑖 𝑘𝑖 );
𝑝−1 𝑝−1
𝑟 𝑟
Let r =1, compute (𝑎 𝑥 ) 𝑝𝑖 ≡ 𝑏 𝑝𝑖 (𝑚𝑜𝑑 𝑝); Substitute x, and expand it, notice that from the
𝑝−1
𝑎0
second term, all the values are since due to the Fermat’s Little Theorem, so it leads to 𝑎 𝑝𝑖
≡
𝑝−1
𝑝𝑖 𝑟
𝑏 (𝑚𝑜𝑑 𝑝); By the former steps, 𝑎0 can be computed in the run-time of O (𝑝𝑖 ), then let 𝑟1 = 𝑟 + 1,
and go back to the third step; Continue the operation above until all the 𝑎𝑖 (1 ≤ 𝑖 ≤ 𝑚) are computed;
For each i, a congruence can be got in the form of second step, then use the Chinese Remainder Theorem
to solve x. The above two algorithms are the two main effective algorithms to solve the Discrete
Logarithm Problem.
5. Conclusion
This research targeted at solving the Discrete Logarithm Problem so to introduce the algorithm to solve
this famous problem, first of all, several important concepts in the field of Elementary Number Theory
are introduced, including the multiplicative order and the primitive root. In addition, several important
theorems are given the rigorous proof like the Primitive Root Theorem, and then this essay turn to focus
on the discrete logarithm, which is the base of the Discrete Logarithm Problem, and the most important
properties of discrete logarithm are introduced. Finally, this research starts to give the solutions to the
Discrete Logarithm Problem but before this, it discusses about why such this problem is designed in
such way and how the previous concept and theories in number theory play an important role in this
problem. Then, the two main algorithms are demonstrated including the Shanks' Babystep-Giantstep
Algorithm and Pohlig-Hellman Discrete Logarithm Algorithm. This research gives the effective
solutions to the Discrete Logarithm Problem and they can work much more efficiently than compute
each value of power, which greatly reduce the run-time of solving this problem.
References
[1] Menezes, A.J., van Oorschot, P.C., Vanstone, S.A. Handbook of Applied Cryptography. CRC
Press.
[2] Burton, D.M. (1989). The Order of an Integer Modulo n. Elementary Number Theory, 4th ed.
[3] Von zur Gathen, J., Jurgen, G. (2013). Modern Computer Algebra. Cambridge University Press.
[4] Gauss, C.F., Clarke, A.A. (translated into English) (1986). Disquisitiones Arithemeticae (Second,
corrected edition), New York: Springer.
[5] Davidson, K.R. (2012). Integers, Polynomials and Finite Fields. University of Waterloo.
[6] Davidson, K.R. (1994). Integer and Polynomial Algebra. University of Waterloo.
[7] Zorzitto, F. (2016). A Taste of Number Theory.
[8] Stromquist, W. (2017). What are Primitive Roots? Mathematics. Bryn Mawr College.
[9] Gauss & Clarke. (1986). Arts 92.
100
Proceedings of the 3rd International Conference on Computing Innovation and Applied Physics
DOI: 10.54254/2753-8818/13/20240801
[10] Shanks, D. (1971). Class number, a theory of factorization and genera. In Proc. Symp. Pure Math.,
Providence, R.I.: American Mathematical Society, vol. 20, pp. 415–440.
[11] Mollin, R. (2006). An Introduction to Cryptography. Chapman and Hall/CRC.p.344.
101