Les professionnels de GBNews.ch s'allient à la puissance des technologies en intelligence artificielle générative, pour informer la communauté des affaires et le grand public, des dernières tendances et des évolutions du marché de l'emploi.

Agenda

Le futur, c’est ...

Du 7 mai 2026 au 10 janvier 2027

À l’ombre des ...

Du 3 juin 2026 au 11 avril 2027

Du Grand Cinéma ...

Du 26 août au 23 décembre 2026

Entrez en matière ...

Du 8 septembre au 18 décembre

La Revue genevoise ...

Du 29 octobre au 31 décembre 2026

Numbers vs. Attackers: The Hidden Mathematics of Encryption

Écrit par Thomas Papas
Paru le 25 novembre 2026

1 The Cleaning Agency Problem

Imagine the following problem: you hire a trustworthy cleaning agency that sends several cleaners to clean your house. The cleaners arrive when you are home but leave when you are at work and have to lock your door, so you must give the agency your house key. The problem is: What if the key gets lost or stolen? Then a stranger could access your house. The solution is, instead of giving a key that locks and unlocks the door to the agency, you give the agency a key that only locks the door, and you keep the only key that unlocks the door, so that if the key gets lost or stolen, a third party cannot access your home.

This is a similar problem to the one described by Whitfield Diffie and Martin E. Hellman in their 1976 paper New Directions in Cryptography [1, pp. 644, 648]. They proposed to use one public key to encrypt (lock the door) and one private key to decrypt (unlock the door) instead of using a single key for both, where deriving the private key from the public key is computationally infeasible: “We will call a task computationally infeasible if its cost [. . .] is finite but impossibly large” [1, p. 646]. However, they said that a method of developing a two-key encryption system (asymmetric cryptography) was “still largely open” [1, p. 644].

 

2 A practical solution of asymmetric cryptography: The RSA Algorithm

A practical algorithm for asymmetric cryptography came from Ronald Rivest, Adi Shamir and Leonard Adleman in their 1978 paper A Method for Obtaining Digital Signatures and Public-Key Cryptosystems [4]. It used the fact that factorizing large natural numbers into prime numbers is believed to be a hard problem, so that the private key cannot be feasibly derived from the public key. It also greatly reduced the need for secure channels to distribute keys: “A public-key cryptosystem needs no private couriers; the keys can be distributed over the insecure communications channel.” [4, p. 121]

2.1 The mathematics of RSA

2.1.1 Primes and factoring

A prime number is a whole number greater than 1 that can only be divided by 1 and itself. For example, 7 is a prime number because it can only be divided by 1 and 7. A famous result on prime numbers is that any whole number greater than 1 can be written as a product of prime numbers. The product is called prime factorization. I will show an example of how this could be computationally hard in a later section.

2.1.2 Modular multiplication with a 24-hour clock

Imagine your computer starts a task at 00:00. It takes 5 hours to complete the task. Therefore, the task will finish at 05:00. Now imagine it has to perform that task 5 times in a row. At what time will it end?

Since completing the task once takes 5 hours, the time to complete the task 5 times is 5 × 5 = 25 hours. However, since there are 24 hours in a day, we divide 25 by 24, which gives us one day with a remainder of one hour. The computer will therefore complete the 5 tasks at 01:00 the next day. This is called multiplication modulo 24 (24 hours in a day). Formally this is written as

5 × 5 mod 24 = 52 mod 24 = 25 mod 24 = 1

Now let’s repeat that 25-hour block 5 times. This is 25 × 5 = 5 × 5 × 5 = 53 = 125 hours. We divide 125 by 24, which gives us five days, with a remainder of five hours. So the computer finishes at 05:00 five days later. Formally, this is written as

53 mod 24 = 125 mod 24 = 5

RSA uses mod n to encrypt a message, where n = p × q, p and q are two large prime numbers chosen by the homeowner in the cleaning problem analogy.

2.1.3 Euler’s totient function, ϕ(n)

Rivest, Shamir and Adleman define Euler’s totient function as: “the number of positive integers less than n which are relatively prime to n” [4, p. 123]. A relatively prime number to n is a number that shares no common factor with n, except for 1. For example, 4 and 15 are relatively prime since they share no common factors, except for 1 (every number greater than 1 that divides 4 does not divide 15).

Let us take n = 15 = 5 × 3 and try to compute ϕ(15). We can easily figure out that 1, 2, 4, 7, 8, 11, 13, 14 are relatively prime to 15 since none of them share common factors with 15. Hence, ϕ(15) = 8. Notice that (5 − 1) × (3 − 1) = 4 × 2 = 8. This is a general rule, for n = p × q, with p and q prime, ϕ(n) = (p − 1)(q − 1) [4, p. 123]. For large n, it is no easier to compute ϕ(n) than to factor n if we do not know p and q, which only the homeowner knows: “We argue that this approach is no easier than factoring n since it enables the cryptanalyst to easily factor n using ϕ(n)” [4, p. 125].

2.1.4 Modular Inverses and the RSA Algorithm

Modular Inverses

In ordinary arithmetic, an inverse of a number a ≠ 0 is 1a since a × 1a = 1. In modular arithmetic, an inverse b modulo m of a number a satisfies

a × b mod m = 1

NB: The inverse exists if and only if a and m are relatively prime.

Recall that 5 × 5 mod 24 = 1. So the inverse of 5 is 5 modulo 24.

The RSA Algorithm

In RSA, the public and private keys are generated as follows:

  1. Choose two large prime numbers p and q.
  2. Calculate n = p × q.
  3. Calculate ϕ(n) = (p − 1)(q − 1).
  4. Choose the public exponent e, an odd, positive integer such that

    216 < e < 2256

    [3, p. 18], and e is relatively prime to ϕ(n).

  5. Calculate the private exponent d, which is the modular inverse of e modulo ϕ(n):

    e × d mod ϕ(n) = 1

Computing d therefore requires knowing ϕ(n); the public key becomes (e, n), whilst the private key is (d, n). Since it is believed to be computationally hard to compute ϕ(n) without knowing p and q for large n, the private key cannot be feasibly derived from the public key if the primes p and q are large enough.

3 Breaking RSA: An Attack on Weak Keys

We have seen how RSA uses prime numbers, modular arithmetic, Euler’s totient function and modular inverses to generate public and private keys.

But what happens if the prime numbers are too small?

To demonstrate this, I built an RSA Security Toolkit in Python that allows an attacker to reconstruct a private key using only publicly available information. This demonstration uses minimal “textbook” RSA and deliberately excludes any additional algorithm that enhances the security of RSA (like padding). Refer to my toolkit for more information.

3.1 The Attack

Suppose Alice (the cleaner) wants to send Bob (the homeowner) the message “HI” using RSA. Bob generates his keys using two small primes. The attacker, Eve (the thief), intercepts the encrypted message and knows Bob’s public key.

In our example, Eve knows:

  • The public modulus n = 2497049351.
  • The public exponent e = 65537.
  • The intercepted ciphertext c = 2322763869.

Eve does not know the private exponent d, nor the prime factors p and q.

3.1.1 Step 1: Factorizing the Public Modulus

Eve attempts to factor n using trial division and a computer. Since the primes are small, she quickly finds:

2497049351 = 40709 × 61339.

Therefore,

p = 40709,   q = 61339.

3.1.2 Step 2: Calculating Euler’s Totient

Now that Eve knows p and q, she can calculate Euler’s totient function:

ϕ(n) = 40708 × 61338

ϕ(n) = 2496947304.

3.1.3 Step 3: Recovering the Private Key

Eve uses the Extended Euclidean Algorithm to find d:

65537d mod 2496947304 = 1.

She obtains:

d = 770073377.

Eve has successfully reconstructed Bob’s private key without ever receiving it from him.

3.1.4 Step 4: Decrypting the Message

RSA decryption uses the private exponent d:

m = cd mod n.

Eve substitutes the intercepted ciphertext and the recovered private exponent:

m = 2322763869770073377 mod 2497049351.

The result is:

m = 18505.

Converting this integer back into two bytes gives:

18505 = 72 × 256 + 73.

In ASCII, 72 corresponds to “H” and 73 to “I”.

Eve has recovered Alice’s original message:

HI.

3.2 Why Did the Attack Work?: Limitations of RSA

The attack succeeded because Bob used very small prime numbers. This made n easy to factor, allowing Eve to calculate ϕ(n) and recover d.

With sufficiently large, properly generated primes, factoring n is believed to be computationally infeasible using currently known classical algorithms. However, some algorithms used in cryptography, including RSA are vulnerable to Shor’s algorithm: “These algorithms are vulnerable to Shor’s Algorithm on a cryptographically relevant quantum computer.” [2, p. 4]. The final version of this NIST report also deprecates RSA at all key sizes after 2030 and disallows it after 2035 [2, p. 14]. The lesson is that RSA security depends not only on its mathematical structure but also on the choice of secure parameters.

 

4 Conclusion

In the cleaning agency story, the homeowner can give the lock-only key to strangers because there is no practical way to derive the unlock key from the lock-only key. In RSA, the known route to the private key is to factor n into p and q, which is believed to be hard. In our attack example, Eve did not break the mathematics of RSA; she exploited Bob's choice of small primes. Bob's n had about 32 bits, against the minimum of 2048 bits required by FIPS 186-5 [3, Sec. 5.1]. Given what happened to Bob, making sure that the generated keys used in encryption meet standards such as FIPS 186-5 is essential for anyone protecting a system.

References

  1. [1] Whitfield Diffie and Martin E. Hellman. New directions in cryptography. IEEE Transactions on Information Theory, 22(6), November 1976.
  2. [2] Dustin Moody, Ray Perlner, Andrew Regenscheid, Angela Robinson, and David Cooper. Transition to post-quantum cryptography standards. NIST Interagency Report NIST IR 8547 (Initial Public Draft), National Institute of Standards and Technology, November 2024.
  3. [3] National Institute of Standards and Technology. Digital signature standard (DSS). Federal Information Processing Standards Publication FIPS 186-5, U.S. Department of Commerce, February 2023.
  4. [4] Ronald L. Rivest, Adi Shamir, and Leonard Adleman. A method for obtaining digital signatures and public-key cryptosystems. Communications of the ACM, 21(2):120–126, February 1978.

Image: Depositphotos 

Thomas Papas

I am a CompTIA Security+ certified analyst with an MSc in Mathematics. My background in mathematics gave me a rigorous, evidence-driven mind: I don’t just react to alerts, I correlate logs, trace root causes and document findings clearly.

Articles connexes :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. Découvrez comment les données de vos commentaires sont traitées.

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram