Why it happens
Why a 2,300-Year-Old Algorithm Is Still in Use
Euclid's algorithm finds two numbers' greatest common divisor by cutting the biggest squares off a rectangle until one fits exactly. Any square that tiles both sides tiles every strip left over, so the answer never changes while the numbers shrink. A 1,920 × 1,080 screen takes 4 divisions to reach 120, and the count grows with digits, not size.
A phone screen cut into squares
- CH1 the strip left
- CH4 the whole rectangle
How to read the stage
- Objective
- Read each round of cuts as one division, and find the greatest common divisor in the last square.
- How this step gets you there
- The text walks the default rectangle's four rounds and ties the picture to the table's divisions.
The rectangle is a phone screen held sideways, 1,920 by 1,080. Each round cuts as many squares as fit off the long side: one of 1,080, one of 840, three of 240, then two of 120, which fit exactly. The table writes each round as one division, such as 1,920 = 1 × 1,080 + 840. So gcd(1,920, 1,080) = 120, and the screen is 16 × 9 squares of 120.
Why the last square is the answer
- Objective
- Explain why cutting squares never loses the greatest common divisor and why the last square's side is it.
- How this step gets you there
- The text follows one square size through the cuts: what tiles the rectangle tiles each strip, and back.
A square tiles the rectangle exactly when its side divides both sides. Any such square also tiles the strip left after a cut, since the strip is a side minus whole squares. So each round keeps the same common divisors while the numbers shrink, and the rounds must end. The last square tiles the strip before it, and so every strip back to the start. No bigger square can, since it would have to fit the last strip too.
Euclid, Elements Book VII
- Objective
- Place the algorithm in Euclid's Elements and tell his subtracting version from the dividing one.
- How this step gets you there
- The text quotes Euclid's own step in translation and Knuth's verdict on how long it has lasted.
Euclid gives the method in the Elements, Book VII, Propositions 1 and 2, around 300 BC. His version subtracts, with "the less of the numbers AB and CD being continually subtracted from the greater", one square at a time. Dividing takes all the squares of one size at once. In Donald Knuth's words, Euclid's method might be called "the granddaddy of all algorithms, because it is the oldest nontrivial algorithm that has survived to the present day."
Fibonacci numbers are the worst case
- Objective
- Say which pairs need the most divisions and why their quotients make them slow.
- How this step gets you there
- The stage colors every pair by its division count and outlines each new record as the scan reaches it.
The second stage runs all 4,656 pairs up to 96 and keeps each pair that needs more divisions than any before it. Every record is a pair of consecutive Fibonacci numbers: 3 and 2, 5 and 3, up to 89 and 55, which take 9. Their quotients are all 1 until the last, the smallest bite a division can take. The average pair takes 3.43.
Every pair up to 96, and its division count
- CH1 the most divisions
- CH2 Lamé's bound
Lamé's bound, 1844
- Objective
- State Lamé's bound and see why it keeps the algorithm fast on huge numbers.
- How this step gets you there
- The bars under the second stage set the most divisions for each digit count against five per digit.
In 1844 Gabriel Lamé proved that the number of divisions is at most five times the number of decimal digits in the smaller number, and his proof runs on Fibonacci numbers. Every pair on the stage stays within it, and some meet it exactly: 13 and 8 take 5 divisions, the bound for a one-digit number. 89 and 55 take 9 against a bound of 10. If the smaller number has 300 digits, the bound is 1,500 divisions.
Where it still runs
- Objective
- Connect the algorithm on the stage to the modular inverse inside RSA key generation.
- How this step gets you there
- The text follows one published key-generation recipe to the step that runs Euclid's divisions.
TLS 1.3, the standard that protects web connections, requires compliant applications to support RSA signatures unless an application profile says otherwise. In the Handbook of Applied Cryptography's recipe for an RSA key, the private key is an exponent d whose product with the public exponent e leaves remainder 1 when divided by φ. The recipe computes d with the extended Euclidean algorithm: the same divisions, with bookkeeping that writes 1 as e × d plus a multiple of φ.
What the model leaves out
- Objective
- Say what counting divisions on small numbers shows and what it leaves out about real running time.
- How this step gets you there
- The text names each simplification: the step it counts, the sizes it runs, and the range it averages.
The stage counts divisions on small numbers, where each division is one step. On numbers hundreds of digits long, each division costs many machine operations, so Lamé's bound counts divisions, not time. The square picture needs whole-number sides. The stage scans pairs only up to 96, so the 3.43 average is for that range.
Questions
- What is the greatest common divisor?
- The largest whole number that divides both numbers with nothing left over. gcd(1,920, 1,080) = 120: 1,920 is 16 × 120 and 1,080 is 9 × 120, and 16 and 9 share no factor, so nothing bigger divides both.
- Why does the Euclidean algorithm work?
- Because big and small have the same common divisors as small and the remainder. Anything dividing big and small divides big minus q times small, which is the remainder. Anything dividing small and the remainder divides q times small plus the remainder, which is big. So each division keeps the answer while shrinking the numbers, until the remainder is 0.
- How many steps does the Euclidean algorithm take?
- At most five divisions per decimal digit of the smaller number, by Lamé's 1844 bound. For pairs up to 96 the most is 9, for 89 and 55, and the average is 3.43. Consecutive Fibonacci numbers are the slowest pairs for their size.
- Is Euclid's algorithm used in RSA?
- Yes, in one standard way of making keys. The Handbook of Applied Cryptography's RSA key generation picks e with gcd(e, φ) = 1 and then uses the extended Euclidean algorithm to find the private exponent d. Using a key afterward is mostly modular exponentiation, not Euclid's algorithm.