
Sequentia Explores: The Mathematics of Crypto
Part II: The Mathematician’s Toolkit
Lecture 12: The Power of Exponents: A Refresher on a Key Cryptographic Tool
In our toolkit so far, we have collected some powerful concepts: modular arithmetic, primes, Euclid’s algorithm, and the abstract structures of Groups and Fields. Today, we’re going to revisit a concept from basic algebra that, when combined with our new tools, becomes one of the most powerful and widely used operations in modern cryptography: exponentiation, or the raising of numbers to a power.
You’ll remember exponents from school. An expression like 3^4 simply means multiplying 3 by itself 4 times:
3^4 = 3 × 3 × 3 × 3 = 81
The basic rules of exponents are also familiar:
- x^a × x^b = x^(a+b)
- (x^a)^b = x^(a×b)
These simple rules are the building blocks. However, in the world of regular arithmetic, exponents cause numbers to grow incredibly quickly. 3^40 is a gigantic number with 19 digits! For cryptography, working with such massive numbers is impractical.
This is where our old friend, modular arithmetic, comes to the rescue.
Modular Exponentiation: Taming the Giant
Modular exponentiation is the process of calculating the remainder of an exponential expression when divided by a modulus. In other words, we are trying to find b^e mod m.
For example, what is 3^4 mod 5?
The Slow Way:
- Calculate 3^4 = 81.
- Find the remainder of 81 ÷ 5. 81 = 16 × 5 + 1. The remainder is 1.
- So, 3^4 ≡ 1 (mod 5).
This works for small numbers. But what about 3^40 mod 5? Or even worse, a real cryptographic problem like 512^1234 mod 7890? Calculating the full value of 512^1234 first would result in a number so astronomically large that no computer on Earth could store it.
The Fast Way: Exponentiation by Squaring (A Glimpse of Efficiency)
Thankfully, the properties of modular arithmetic allow for a much more efficient method. Because we can apply the modulo at each intermediate step of a calculation, we can keep the numbers from ever growing too large.
A common technique is known as exponentiation by squaring (or binary exponentiation). The details of the algorithm are a bit much for this lecture, but the core idea is to break down the exponent into powers of two, calculate intermediate results by repeated squaring, and apply the modulo at every single step.
Let’s see a simpler version of the “apply modulo at each step” idea for 3^4 mod 5:
- 3^1 ≡ 3 (mod 5)
- 3^2 = 9 ≡ 4 (mod 5)
- 3^3 = 3^2 × 3 ≡ 4 × 3 = 12 ≡ 2 (mod 5)
- 3^4 = 3^3 × 3 ≡ 2 × 3 = 6 ≡ 1 (mod 5)
Notice how the number we are working with never exceeds 5 × 3 = 15. Using this principle, a computer can efficiently calculate 512^1234 mod 7890 in a fraction of a second without ever dealing with gigantic intermediate numbers.
This ability to efficiently compute enormous powers within a finite field is a cornerstone of modern cryptographic algorithms.
The “Hard Problem” that Creates Security
Here we arrive at another beautiful asymmetry in mathematics, similar to what we saw with prime numbers.
- Easy Task (Modular Exponentiation): Given a base g, an exponent x, and a modulus p, calculating the result r = (g^x) mod p is computationally easy and fast, even for very large numbers.
- Hard Task (The Discrete Logarithm Problem): Given the base g, the modulus p, and the result r, trying to find the original exponent x is computationally extremely difficult for well-chosen large numbers.
This is known as the Discrete Logarithm Problem (DLP). Like integer factorization, it is another “trapdoor function”—easy to do one way, nearly impossible to reverse.
For example:
- Easy: It’s simple to calculate 3^8 mod 17. The answer is 6561 mod 17, which equals 16.
- Hard: Now, solve for x in the equation 3^x ≡ 16 (mod 17). You might find x=8 by trial and error here. But if the modulus was a 300-digit prime number, there is no known efficient algorithm to find x. You’d have to try trillions upon trillions of possibilities.
The Foundation of Diffie-Hellman and Others
This “hard problem” is the security foundation for several critical cryptographic protocols, most famously the Diffie-Hellman key exchange.
In Diffie-Hellman, Alice and Bob can agree on a shared secret key over a public channel (where Eve is listening) without ever sending the key itself! They do this by each choosing a secret exponent, performing a modular exponentiation, and exchanging the public results. Through a clever mathematical trick (which relies on the rules of exponents), they can both independently calculate the same final shared secret, while Eve, who only sees the public results, is stuck trying to solve the impossibly hard Discrete Logarithm Problem.
We’ll dissect Diffie-Hellman in a future lecture, but for now, the key takeaway is this: the combination of simple exponent rules and the cyclical nature of modular arithmetic creates a powerful one-way operation.
Exponents, tamed by the world of modulo, are not just for calculating growth rates. They are for building cryptographic trapdoors that allow us to share secrets in plain sight.
In our next lecture, we’ll shift gears slightly and talk about probability and randomness—the art of generating unpredictable secrets in the first place.