ViewWiki

Lesson 1 of 4

Clock arithmetic.

About 20 minutes · 6 practice questions

Modular arithmetic: a remainder as a place on a clock, addition that wraps back to zero, and powers that leap around the dial and in the end return to 1.

Step 1 of 6 · Remainders

Step 1 of 6

Remainders

Today’s encryption is built on arithmetic in which numbers never grow: they wrap round. When you divide a whole number aa⁠ by a number nn⁠, a remainder between 00⁠ and n−1n - 1⁠ is left. That remainder is written a mod na \bmod n⁠, read “aa⁠ mod nn⁠”.

In the Scene, Alice and Bob are at either end of an open tube, and Eve listens in the middle. Look inside is open at The maths: in the middle of the board stands a dial with 2323⁠ places, 00⁠ to 2222⁠, like a clock. Every number lands on the place of its remainder on dividing by 2323⁠.

To the question

Step 2 of 6

Round the clock

An ordinary clock is arithmetic mod 1212⁠: after 1111⁠ comes 00⁠ again, which we call 1212⁠. To know the time in a few hours, add and take the remainder. The same works for multiplication: you can take the remainder after every step, and the result does not change.

To the question

Step 3 of 6

Powers mod p

A key exchange does not add but raises to powers. Choose a prime pp⁠, here 2323⁠, and a number gg⁠, here 55⁠. Alice chooses a secret number aa⁠ and works out

A=ga mod pA = g^a \bmod p⁠

Alice’s secret is now fixed at a=2a = 2⁠, and the maths is hidden. Work out AA⁠ yourself.

To the question

Step 4 of 6

Step by step

There is no need to work out 5105^{10}⁠, an eight-digit number, to know what 510 mod 235^{10} \bmod 23⁠ is. Each power is the one before times gg⁠, and you can take the remainder after every multiplication. That way the numbers always stay smaller than pp⁠, and that is how powers of numbers hundreds of digits long are worked out too.

Change Alice’s secret and watch her board and her hand on the dial.

To the question

Step 5 of 6

Leaps

The powers of 55⁠ mod 2323⁠ do not rise in order: 55⁠, 22⁠, 1010⁠, and then a jump. The hand leaps around the dial, and there is no way to know where it will land without working it out.

To the question

Step 6 of 6

A full circle

Mod 2323⁠, 55⁠ has a special property: its powers reach every place on the dial except 00⁠, each place once. Such a number is called a generator. In the last Lesson of this Unit it will be the gg⁠ of the key exchange.

To the question

Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Calculate

What is 17 mod 517 \bmod 5⁠?

To the experiment

Practice · Calculate

The clock shows 99⁠. What will it show in 88⁠ hours? (On a 1212⁠-hour clock, with 1212⁠ written here as 00⁠.)

To the experiment

Practice · Calculate

The arithmetic runs mod p=23p = 23⁠, with g=5g = 5⁠. Alice’s secret is fixed at a=2a = 2⁠. What does she send, A=52 mod 23A = 5^2 \bmod 23⁠?

To the experiment

Practice · Reach the target

Change Alice’s secret until A=5a mod 23A = 5^a \bmod 23⁠ is 1010⁠, then press Check.

To the experiment

Practice · Predict, then look

At a=3a = 3⁠, A=10A = 10⁠. What will AA⁠ be when Alice’s secret goes up to a=4a = 4⁠? Write a number, and then the Scene moves to a=4a = 4⁠.

To the experiment

Practice · Predict, then look

The powers of 55⁠ mod 2323⁠ leap around the dial. What will A=522 mod 23A = 5^{22} \bmod 23⁠ be? Choose, and then Alice’s secret moves to 2222⁠.