ViewWiki

Answer key · Unit 7

Cryptography.

Each lesson’s practice questions, their correct answers and the mistakes they spot. Answers read off the Scene use the same setting the learner sees.

Lesson 1 of 4 · About 20 minutes

Clock arithmetic

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.

Open the lesson

The 6 steps and their answers
  1. Step 1 of 6

    Open this step

    Remainders

    Practice · Calculate

    Question

    What is 17 mod 517 \bmod 5⁠?

    Correct answer

    2 ± 0.01

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6
    Locked message / The maths
    The maths
    Accepted within
    ± 0.01
    A fixed value in the question

    Wrong answers it recognises

    • 3 ± 0.01

      Misconception: Gives the quotient of the division (how many times it goes in) instead of the remainder.

      Feedback from the catalogue

      “a mod na \bmod n⁠” is the remainder when aa⁠ is divided by nn⁠, not the result of the division. In 17÷517 \div 5⁠ five goes in 33⁠ times, 3×5=153 \times 5 = 15⁠, and 22⁠ is left: so 17 mod 5=217 \bmod 5 = 2⁠. The remainder is always between 00⁠ and n−1n - 1⁠, like a place on a clock with nn⁠ places.

    • 3.4 ± 0.01

      Misconception: Gives the quotient of the division (how many times it goes in) instead of the remainder.

      Feedback from the catalogue

      “a mod na \bmod n⁠” is the remainder when aa⁠ is divided by nn⁠, not the result of the division. In 17÷517 \div 5⁠ five goes in 33⁠ times, 3×5=153 \times 5 = 15⁠, and 22⁠ is left: so 17 mod 5=217 \bmod 5 = 2⁠. The remainder is always between 00⁠ and n−1n - 1⁠, like a place on a clock with nn⁠ places.

    Feedback for a right answer

    17=3×5+217 = 3 \times 5 + 2⁠, so 17 mod 5=217 \bmod 5 = 2⁠. On a clock with 55⁠ places, 00⁠ to 44⁠, a step of 1717⁠ from 00⁠ goes round three times and lands on 22⁠.

    Hint

    How many times does 55⁠ go into 1717⁠, and what is left?

    Worked solution

    1. Divide: 55⁠ goes into 1717⁠ three times, 3×5=153 \times 5 = 15⁠.
    2. The remainder: 17−15=217 - 15 = 2⁠.
    3. So 17 mod 5=217 \bmod 5 = 2⁠.

    If you answered 33⁠ or 3.43.4⁠, you gave the result of the division. “Mod” keeps only what is left over.

  2. Step 2 of 6

    Open this step

    Round the clock

    Practice · Calculate

    Question

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

    Correct answer

    5 ± 0.01

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6
    Locked message / The maths
    The maths
    Accepted within
    ± 0.01
    A fixed value in the question

    Wrong answers it recognises

    • 17 ± 0.01

      Misconception: Forgets to wrap round: gives the plain result instead of its remainder mod n.

      Feedback from the catalogue

      In modular arithmetic every result wraps back onto the clock: after n−1n - 1⁠ comes 00⁠. Nine o’clock plus 88⁠ hours is not 1717⁠ on a 1212⁠-hour clock, but 17 mod 12=517 \bmod 12 = 5⁠. Powers too: 52=255^2 = 25⁠, but 52 mod 23=25^2 \bmod 23 = 2⁠. After each calculation, divide by nn⁠ and keep only the remainder.

    Feedback for a right answer

    9+8=179 + 8 = 17⁠, and 17 mod 12=517 \bmod 12 = 5⁠: five o’clock. That is modular arithmetic, clock arithmetic: each time you pass 1212⁠, you start again from zero.

    Hint

    Add, then find the remainder on dividing by 1212⁠.

    Worked solution

    1. Add: 9+8=179 + 8 = 17⁠.
    2. On a 1212⁠-hour clock: 17=1×12+517 = 1 \times 12 + 5⁠.
    3. 17 mod 12=517 \bmod 12 = 5⁠, and the clock shows 55⁠.

    If you answered 1717⁠, you forgot to wrap round: the clock has no place 1717⁠.

  3. Step 3 of 6

    Open this step

    Powers mod p

    Practice · Calculate

    Question

    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⁠?

    Correct answer

    2 ± 0.01

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    2fixed
    Locked message / The maths
    Mixing paintfixed
    Accepted within
    ± 0.01
    Computed from the Scene at this step’s setting
    What Alice sends, A = gᵃ mod p/nodes/kx/outputs/alicePublic

    Wrong answers it recognises

    • 25 ± 0.01

      Misconception: Forgets to wrap round: gives the plain result instead of its remainder mod n.

      Feedback from the catalogue

      In modular arithmetic every result wraps back onto the clock: after n−1n - 1⁠ comes 00⁠. Nine o’clock plus 88⁠ hours is not 1717⁠ on a 1212⁠-hour clock, but 17 mod 12=517 \bmod 12 = 5⁠. Powers too: 52=255^2 = 25⁠, but 52 mod 23=25^2 \bmod 23 = 2⁠. After each calculation, divide by nn⁠ and keep only the remainder.

    • 10 ± 0.01

      Misconception: Multiplies the base by the exponent (5 × 6) instead of raising it to that power (5⁶).

      Feedback from the catalogue

      gag^a⁠ means multiplying gg⁠ by itself aa⁠ times, not multiplying gg⁠ by aa⁠. 53=5×5×5=1255^3 = 5 \times 5 \times 5 = 125⁠, not 5×3=155 \times 3 = 15⁠. Mod pp⁠ you do it step by step: each power is the one before times gg⁠, then the remainder. From 52 mod 23=25^2 \bmod 23 = 2⁠ you get 53 mod 23=2×5=105^3 \bmod 23 = 2 \times 5 = 10⁠.

    • 1 ± 0.01

      Misconception: Gives the quotient of the division (how many times it goes in) instead of the remainder.

      Feedback from the catalogue

      “a mod na \bmod n⁠” is the remainder when aa⁠ is divided by nn⁠, not the result of the division. In 17÷517 \div 5⁠ five goes in 33⁠ times, 3×5=153 \times 5 = 15⁠, and 22⁠ is left: so 17 mod 5=217 \bmod 5 = 2⁠. The remainder is always between 00⁠ and n−1n - 1⁠, like a place on a clock with nn⁠ places.

    Feedback for a right answer

    52=25=1×23+25^2 = 25 = 1 \times 23 + 2⁠, so A=2A = 2⁠. On the dial with 2323⁠ places, Alice’s hand points at 22⁠.

    Hint

    Work out 525^2⁠, then its remainder on dividing by 2323⁠.

    Worked solution

    1. 52=5×5=255^2 = 5 \times 5 = 25⁠.
    2. 25=1×23+225 = 1 \times 23 + 2⁠.
    3. A=25 mod 23=2A = 25 \bmod 23 = 2⁠.

    If you answered 2525⁠, you did not take the remainder. If you answered 1010⁠, you multiplied 5×25 \times 2⁠ instead of squaring. If you answered 11⁠, you gave the result of the division, not the remainder.

  4. Step 4 of 6

    Open this step

    Step by step

    Practice · Reach the target

    Question

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

    Goal

    • 10 ± 0.1

      At the start of the step: 5

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    1
    Locked message / The maths
    The mathsfixed
    Read from the Scene at
    What Alice sends, A = gᵃ mod p/nodes/kx/outputs/alicePublic

    One setting that reaches it

    Alice's secret
    3

    Feedback for a right answer

    a=3a = 3⁠: 53 mod 23=(52 mod 23)×5 mod 23=2×5=105^3 \bmod 23 = (5^2 \bmod 23) \times 5 \bmod 23 = 2 \times 5 = 10⁠. There is no need to work out 53=1255^3 = 125⁠: you can take the remainder after every multiplication, and the numbers stay small. That is how powers of numbers hundreds of digits long are worked out.

    Feedback for a wrong answer

    Not yet. Watch Alice’s board: it shows AA⁠ for every aa⁠.

    Hint

    Each power is the one before times 55⁠, then the remainder: 51 mod 23=55^1 \bmod 23 = 5⁠, 52 mod 23=25^2 \bmod 23 = 2⁠, and next?

    Worked solution

    1. 51 mod 23=55^1 \bmod 23 = 5⁠.
    2. 52 mod 23=5×5 mod 23=25 mod 23=25^2 \bmod 23 = 5 \times 5 \bmod 23 = 25 \bmod 23 = 2⁠.
    3. 53 mod 23=2×5 mod 23=105^3 \bmod 23 = 2 \times 5 \bmod 23 = 10⁠.
    4. Set Alice’s secret to 33⁠.

    If you tried a=2a = 2⁠, you got A=2A = 2⁠: 5×2=105 \times 2 = 10⁠ is multiplication, not a power.

  5. Step 5 of 6

    Open this step

    Leaps

    Practice · Predict, then look

    Question

    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⁠.

    Correct answer

    4 ± 0.1

    A number prediction counts as right within ± 0.1

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    3fixed
    Locked message / The maths
    The mathsfixed

    Once the prediction is locked in, the Scene changes

    Alice's secret
    4fixed

    The Scene then shows: 4 · What Alice sends, A = gᵃ mod p/nodes/kx/outputs/alicePublic

    A prediction is never marked as a failure: the learner sees the outcome and the explanation either way.

    Feedback for a right answer

    10×5=50=2×23+410 \times 5 = 50 = 2 \times 23 + 4⁠, so A=4A = 4⁠. The hand jumped back from 1010⁠ to 44⁠: powers mod pp⁠ do not grow in order, they leap around the clock. That is exactly what makes them hard to guess.

    Feedback for a wrong answer

    Multiply the last AA⁠, 1010⁠, by g=5g = 5⁠, and take the remainder on dividing by 2323⁠.

    Hint

    Multiply 1010⁠ by 55⁠ and take the remainder on dividing by 2323⁠.

    Worked solution

    1. 54=53×55^4 = 5^3 \times 5⁠, so 54 mod 23=(53 mod 23)×5 mod 235^4 \bmod 23 = (5^3 \bmod 23) \times 5 \bmod 23⁠.
    2. 10×5=5010 \times 5 = 50⁠.
    3. 50=2×23+450 = 2 \times 23 + 4⁠.
    4. A=4A = 4⁠.

    If you wrote 5050⁠, you forgot to wrap round the clock. If you wrote 1515⁠, you added 55⁠ instead of multiplying by it.

  6. Step 6 of 6

    Open this step

    A full circle

    Practice · Predict, then look

    Question

    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⁠.

    Correct answer

    • Correct 11⁠: after 2222⁠ steps the powers come back to the start

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    3fixed
    Locked message / The maths
    The mathsfixed

    Choices

    • Correct 11⁠: after 2222⁠ steps the powers come back to the start

    • Wrong 2222⁠, the last place on the dial

      Feedback

      There is no reason the 2222⁠nd power should land on place 2222⁠: the powers leap about, and 511 mod 235^{11} \bmod 23⁠ already lands there.

    • Wrong 00⁠: the power is so big that it reaches a multiple of 2323⁠

      Feedback

      5225^{22}⁠ is a product of fives only, and 2323⁠ is prime, so 2323⁠ never divides it: the remainder is never 00⁠, however large the exponent.

    Once the prediction is locked in, the Scene changes

    Alice's secret
    22fixed

    The Scene then shows: 1 · What Alice sends, A = gᵃ mod p/nodes/kx/outputs/alicePublic

    A prediction is never marked as a failure: the learner sees the outcome and the explanation either way.

    Feedback for a right answer

    522 mod 23=15^{22} \bmod 23 = 1⁠. The powers of 55⁠, from 515^1⁠ to 5225^{22}⁠, pass through all 2222⁠ non-zero places, each once, and come back to 11⁠. From there they repeat: 523 mod 23=55^{23} \bmod 23 = 5⁠. A number like 55⁠, whose powers reach every place, is called a generator, and it is what a key exchange uses.

    Hint

    The dial has 2222⁠ places besides 00⁠. If 55⁠ reaches each of them exactly once, where do you arrive after a full round?

    Worked solution

    1. The powers of 55⁠ mod 2323⁠: 5, 2, 10, 4, 20, 8, 17, 16, 11, 9, 22, 18, 21, 13, 19, 3, 15, 6, 7, 12, 14, 1.
    2. These are 2222⁠ different numbers: every place on the dial except 00⁠.
    3. The 2222⁠nd power is 11⁠, and from there the sequence starts again.

    This is a case of Fermat’s little theorem: when pp⁠ is prime and gg⁠ is not divisible by it, gp−1 mod p=1g^{p-1} \bmod p = 1⁠.

Lesson 2 of 4 · About 25 minutes

Prime numbers

What makes a number prime, how the sieve of Eratosthenes finds them all, why they thin out, and why primes are easy to multiply and hard to find again.

Open the lesson

The 6 steps and their answers
  1. Step 1 of 6

    Open this step

    What a prime is

    Practice · Choose

    Question

    Which of these numbers are prime? Choose all of them.

    Correct answer

    • Correct 22⁠

    • Correct 9797⁠

    Setup, choices and feedback

    The Scene at this step

    Count up to
    100
    Sieve the spiral
    Spiralfixed

    Choices

    More than one choice is correct: every one must be selected.

    • Wrong 11⁠

      Misconception: Counts 1 as a prime number.

      Feedback from the catalogue

      A prime is a whole number with exactly two divisors: 11⁠ and itself. 11⁠ has only one divisor, so it is neither prime nor composite. The definition was chosen so that every number has only one way to be written as a product of primes: if 11⁠ were prime, you could write 6=2×3=1×2×36 = 2 \times 3 = 1 \times 2 \times 3⁠ and in endless other ways.

    • Correct 22⁠

    • Wrong 5151⁠

      Misconception: Takes an odd number that has no obvious small factor, such as 51, 91 or 99, to be prime.

      Feedback from the catalogue

      An odd number is not divisible by 22⁠, but it can be divisible by 33⁠, 77⁠ or any other prime. 51=3×1751 = 3 \times 17⁠, 91=7×1391 = 7 \times 13⁠ and 99=9×1199 = 9 \times 11⁠. To know a number is prime, check that no prime up to its square root divides it: for 9191⁠, check 22⁠, 33⁠, 55⁠ and 77⁠, and 77⁠ divides it.

    • Wrong 9191⁠

      Misconception: Takes an odd number that has no obvious small factor, such as 51, 91 or 99, to be prime.

      Feedback from the catalogue

      An odd number is not divisible by 22⁠, but it can be divisible by 33⁠, 77⁠ or any other prime. 51=3×1751 = 3 \times 17⁠, 91=7×1391 = 7 \times 13⁠ and 99=9×1199 = 9 \times 11⁠. To know a number is prime, check that no prime up to its square root divides it: for 9191⁠, check 22⁠, 33⁠, 55⁠ and 77⁠, and 77⁠ divides it.

    • Correct 9797⁠

    Feedback for a right answer

    22⁠ and 9797⁠. 22⁠ is the only even prime. 9797⁠ is not divisible by 22⁠, 33⁠, 55⁠ or 77⁠, and that is enough, because 112=12111^2 = 121⁠ is already bigger. 51=3×1751 = 3 \times 17⁠, 91=7×1391 = 7 \times 13⁠, and 11⁠ is not prime: it has only one divisor.

    Hint

    For each number, try dividing it by the primes 22⁠, 33⁠, 55⁠ and 77⁠.

    Worked solution

    1. 11⁠: it has only one divisor, so it is not prime.
    2. 22⁠: its divisors are 11⁠ and 22⁠. Prime.
    3. 5151⁠: its digit sum, 66⁠, is divisible by 33⁠, and 51=3×1751 = 3 \times 17⁠. Composite.
    4. 91=7×1391 = 7 \times 13⁠. Composite.
    5. 9797⁠: not divisible by 22⁠, 33⁠, 55⁠ or 77⁠, and 97<10\sqrt{97} < 10⁠. Prime.

    Numbers like 5151⁠ and 9191⁠ “look” prime because they are odd and do not end in 55⁠. You have to check every prime up to the square root.

  2. Step 2 of 6

    Open this step

    The largest below a hundred

    Practice · Calculate

    Question

    Count up to is fixed at 100100⁠. What is the largest prime up to 100100⁠?

    Correct answer

    97 ± 0.1

    Setup, choices and feedback

    The Scene at this step

    Count up to
    100fixed
    Sieve the spiral
    Spiralfixed
    Accepted within
    ± 0.1
    Computed from the Scene at this step’s setting
    The largest prime from 1 to count/nodes/spiral/outputs/largestPrime

    Wrong answers it recognises

    • 99 ± 0.1

      Misconception: Takes an odd number that has no obvious small factor, such as 51, 91 or 99, to be prime.

      Feedback from the catalogue

      An odd number is not divisible by 22⁠, but it can be divisible by 33⁠, 77⁠ or any other prime. 51=3×1751 = 3 \times 17⁠, 91=7×1391 = 7 \times 13⁠ and 99=9×1199 = 9 \times 11⁠. To know a number is prime, check that no prime up to its square root divides it: for 9191⁠, check 22⁠, 33⁠, 55⁠ and 77⁠, and 77⁠ divides it.

    Feedback for a right answer

    9797⁠. 100100⁠ and 9898⁠ are even, 99=9×1199 = 9 \times 11⁠, and 9797⁠ is divisible by none of the primes 22⁠, 33⁠, 55⁠ and 77⁠. On the tray it is a raised gold tile.

    Hint

    Work down from 100100⁠ and check each odd number.

    Worked solution

    1. 100100⁠ and 9898⁠ are even: composite.
    2. 9999⁠: its digit sum, 1818⁠, is divisible by 33⁠, and 99=9×1199 = 9 \times 11⁠. Composite.
    3. 9797⁠: check the primes up to 97≈9.8\sqrt{97} \approx 9.8⁠, that is 22⁠, 33⁠, 55⁠ and 77⁠. None of them divides it.
    4. 9797⁠ is the largest prime up to 100100⁠.

    If you answered 9999⁠, it is odd but divisible by 33⁠ and by 1111⁠.

  3. Step 3 of 6

    Open this step

    The sieve

    Practice · Predict, then look

    Question

    Count up to is 400400⁠. The sieve of Eratosthenes circles a prime, crosses out its multiples, and moves on to the next prime. Through how many primes must it go before every tile left is prime? Choose, and then Sieve the spiral runs the sieve to the end.

    Correct answer

    • Correct 88⁠: the primes up to 2020⁠

    Setup, choices and feedback

    The Scene at this step

    Count up to
    400fixed
    Sieve the spiral
    Spiralfixed

    Choices

    • Correct 88⁠: the primes up to 2020⁠

    • Wrong 7878⁠: every prime up to 400400⁠

      Misconception: Thinks the sieve must cross out multiples of every prime up to the count, not just of the primes up to its square root.

      Feedback from the catalogue

      A composite number up to nn⁠ always has a prime factor no bigger than n\sqrt{n}⁠: if both its factors were bigger than n\sqrt{n}⁠, their product would be bigger than nn⁠. So once the sieve has run through the primes up to n\sqrt{n}⁠, every composite has been crossed out. Up to 400400⁠, 400=20\sqrt{400} = 20⁠, and eight primes are enough: 22⁠ to 1919⁠.

    • Wrong 44⁠: the primes 22⁠, 33⁠, 55⁠ and 77⁠

      Feedback

      22⁠, 33⁠, 55⁠ and 77⁠ are enough up to 120120⁠, but not up to 400400⁠: 112=12111^2 = 121⁠, 132=16913^2 = 169⁠, 172=28917^2 = 289⁠ and 192=36119^2 = 361⁠ are composites none of them crosses out.

    Once the prediction is locked in, the Scene changes

    Sieve the spiral
    0.62 (Spiral → Sieve and gaps)fixed

    The Scene then shows: 8 · How many primes the sieve runs through (those up to √count)/nodes/spiral/outputs/sievingPrimes

    A prediction is never marked as a failure: the learner sees the outcome and the explanation either way.

    Feedback for a right answer

    Eight: 2,3,5,7,11,13,17,192, 3, 5, 7, 11, 13, 17, 19⁠. Every composite up to 400400⁠ is divisible by a prime no bigger than 400=20\sqrt{400} = 20⁠, so after 1919⁠ there is nothing left to cross out. The sieve starts crossing each prime’s multiples from its square, because the smaller ones are gone already.

    Hint

    A composite number up to 400400⁠ has a prime factor no bigger than 400\sqrt{400}⁠.

    Worked solution

    1. If n=a×bn = a \times b⁠ and both factors are bigger than 2020⁠, then n>400n > 400⁠.
    2. So every composite up to 400400⁠ has a prime factor no bigger than 2020⁠.
    3. The primes up to 2020⁠: 2,3,5,7,11,13,17,192, 3, 5, 7, 11, 13, 17, 19⁠. Eight.
    4. Once the sieve has gone through them, every tile left is prime.

    If you chose 7878⁠, the sieve would carry on for nothing: 2323⁠ has no composite multiple up to 400400⁠ that is not crossed out already, since 232=52923^2 = 529⁠.

  4. Step 4 of 6

    Open this step

    Thinning out

    Practice · Reach the target

    Question

    Up to 100100⁠ there are 2525⁠ primes. Change Count up to until the slate shows 168168⁠ primes, then press Check.

    Goal

    • 168 ± 0.1

      At the start of the step: 25

    Setup, choices and feedback

    The Scene at this step

    Count up to
    100
    Sieve the spiral
    Spiralfixed
    Read from the Scene at
    How many primes there are from 1 to count/nodes/spiral/outputs/primeCount

    One setting that reaches it

    Count up to
    1000

    Feedback for a right answer

    At 10001000⁠. Ten times as many numbers, but only 6.76.7⁠ times as many primes: up to 100100⁠ a quarter of the numbers are prime, and up to 10001000⁠ under a sixth. The bigger a number, the more small primes there are that might divide it.

    Feedback for a wrong answer

    Not yet. The slate behind the tray counts the primes. Keep counting further.

    Hint

    If the primes kept their density, 168168⁠ would come at about 700700⁠. They do not.

    Worked solution

    1. Move Count up to and watch the number of primes on the slate.
    2. Up to 900900⁠ there are 154154⁠ primes, and up to 11001100⁠ there are 184184⁠.
    3. Exactly 168168⁠ comes at 10001000⁠.

    If you expected 168168⁠ around 700700⁠, you assumed the primes keep to a quarter of the numbers. They thin out.

  5. Step 5 of 6

    Open this step

    An eighth

    Practice · Calculate

    Question

    Count up to is fixed at 10 00010\,000⁠, and the slate shows how many primes there are up to there. What share of the numbers up to 10 00010\,000⁠ is prime? Answer in per cent.

    Correct answer

    12.29 ± 0.05

    Setup, choices and feedback

    The Scene at this step

    Count up to
    10000fixed
    Sieve the spiral
    Spiralfixed
    Accepted within
    ± 0.05
    Computed from the Scene at this step’s setting
    How many primes there are from 1 to count/nodes/spiral/outputs/primeCount

    Wrong answers it recognises

    • 25 ± 0.05

      Misconception: Thinks primes keep the same share of the numbers however far you count, as the quarter below 100.

      Feedback from the catalogue

      The primes thin out. Up to 100100⁠ there are 2525⁠, a quarter of the numbers; up to 10001000⁠ there are 168168⁠, under a sixth; up to 10 00010\,000⁠ there are 12291229⁠, about an eighth. The bigger a number, the more smaller primes there are that might divide it. The chance that a number near nn⁠ is prime is about 1ln⁡n\tfrac{1}{\ln n}⁠, which shrinks slowly. And still they never run out: Euclid proved there are infinitely many primes.

    • 16.8 ± 0.05

      Misconception: Thinks primes keep the same share of the numbers however far you count, as the quarter below 100.

      Feedback from the catalogue

      The primes thin out. Up to 100100⁠ there are 2525⁠, a quarter of the numbers; up to 10001000⁠ there are 168168⁠, under a sixth; up to 10 00010\,000⁠ there are 12291229⁠, about an eighth. The bigger a number, the more smaller primes there are that might divide it. The chance that a number near nn⁠ is prime is about 1ln⁡n\tfrac{1}{\ln n}⁠, which shrinks slowly. And still they never run out: Euclid proved there are infinitely many primes.

    Feedback for a right answer

    122910 000≈12.3%\tfrac{1229}{10\,000} \approx 12.3\%⁠: about an eighth of the numbers. Up to 100100⁠ it was a quarter, and up to 10001000⁠ about a sixth. The density falls roughly like 1ln⁡n\tfrac{1}{\ln n}⁠, slowly, and never reaches zero.

    Hint

    Divide the number of primes by 10 00010\,000⁠ and multiply by 100100⁠.

    Worked solution

    1. The slate shows 12291229⁠ primes up to 10 00010\,000⁠.
    2. The share: 122910 000=0.1229\tfrac{1229}{10\,000} = 0.1229⁠.
    3. In per cent: 12.29%12.29\%⁠.

    If you answered 25%25\%⁠ or 16.8%16.8\%⁠, you used the density up to 100100⁠ or up to 10001000⁠. The primes thin out as you count further.

  6. Step 6 of 6

    Open this step

    One easy direction

    Practice · Choose

    Question

    Multiplying is easy: 89×97=863389 \times 97 = 8633⁠. Now the other way round: someone gives you only 86338633⁠. What is true of it?

    Correct answer

    • Correct It is a product of two primes, and finding them takes far longer than multiplying them

    Setup, choices and feedback

    The Scene at this step

    Count up to
    10000
    Sieve the spiral
    Sieve and gaps

    Choices

    Shown in a random order.

    • Correct It is a product of two primes, and finding them takes far longer than multiplying them

    • Wrong It is prime, because it is not divisible by 22⁠, 33⁠, 55⁠ or 77⁠

      Misconception: Takes an odd number that has no obvious small factor, such as 51, 91 or 99, to be prime.

      Feedback from the catalogue

      An odd number is not divisible by 22⁠, but it can be divisible by 33⁠, 77⁠ or any other prime. 51=3×1751 = 3 \times 17⁠, 91=7×1391 = 7 \times 13⁠ and 99=9×1199 = 9 \times 11⁠. To know a number is prime, check that no prime up to its square root divides it: for 9191⁠, check 22⁠, 33⁠, 55⁠ and 77⁠, and 77⁠ divides it.

    • Wrong Its factors are found as fast as you multiply

      Feedback

      To find the factors you have to try primes one after another, up to 8633≈93\sqrt{8633} \approx 93⁠: twenty-four tries, and only the last, 8989⁠, works. All that instead of one multiplication.

    Feedback for a right answer

    8633=89×978633 = 89 \times 97⁠. Multiplying takes a moment, but the simple way to factor is to try primes one after another, and here you must get as far as 8989⁠. For numbers hundreds of digits long multiplying still takes a moment, and no fast way to factor is known. Cryptography rests on that gap between an easy direction and a hard one.

    Hint

    To know whether 86338633⁠ is prime, you must check every prime up to 8633\sqrt{8633}⁠. How far is that?

    Worked solution

    1. 8633≈92.9\sqrt{8633} \approx 92.9⁠, so you must check the primes up to 8989⁠.
    2. 22⁠, 33⁠, 55⁠, 77⁠ and nineteen more primes, up to 8383⁠, do not divide 86338633⁠.
    3. 8989⁠ does: 8633÷89=978633 \div 89 = 97⁠.
    4. 8633=89×978633 = 89 \times 97⁠, a product of two primes.

    If you thought it prime, you stopped too soon: checking up to 77⁠ is enough only for numbers up to 120120⁠.

Lesson 3 of 4 · About 20 minutes

Keys and guessing

A message locked with a key, the trouble of passing the key, and why every extra bit in the key doubles the time a codebreaker needs to try them all.

Open the lesson

The 6 steps and their answers
  1. Step 1 of 6

    Open this step

    A locked message

    Practice · Choose

    Question

    Alice wants to send Bob a message locked with a key. Eve copies everything that passes through the tube. What is the trouble with first sending the key down the same tube?

    Correct answer

    • Correct Eve copies the key too, and opens every message with it

    Setup, choices and feedback

    The Scene at this step

    Key size
    56 bits
    Unlock step by step
    Locked messagefixed

    Choices

    Shown in a random order.

    • Correct Eve copies the key too, and opens every message with it

    • Wrong No trouble: the key is short, and Eve will not notice it

      Feedback

      Eve copies every capsule that passes, short or long. A key that went down the open tube is hers too.

    • Wrong No trouble: lock the key with a second key

      Feedback

      Then Bob needs the second key, and down which tube? The problem only moves one step back. That is why for generations keys travelled by hand, by courier and at meetings.

    Feedback for a right answer

    A key that crossed an open channel is no longer secret. That is the key distribution problem: to talk in secret you need a shared key, and to pass a key you need a secret channel. In the next Lesson you will see how Diffie and Hellman solved it in 1976.

    Hint

    What can Eve do with anything she copies?

    Worked solution

    1. Everything that passes through the tube reaches Eve too.
    2. If the key goes down the tube, Eve has the same key as Bob.
    3. With it she opens every message locked with it.

    Locking the key with a second key does not help: the second key has to travel the same way.

  2. Step 2 of 6

    Open this step

    Counting keys

    Practice · Calculate

    Question

    Key size is fixed at 88⁠ bits, and Eve’s machine board shows 28=2562^8 = 256⁠ keys to try. How many different keys are there at 1616⁠ bits?

    Correct answer

    65540 ± 0.5

    Setup, choices and feedback

    The Scene at this step

    Key size
    8 bitsfixed
    Unlock step by step
    Locked messagefixed
    Accepted within
    ± 0.5
    A fixed value in the question

    Wrong answers it recognises

    Feedback for a right answer

    216=65 5362^{16} = 65\,536⁠. Eight more bits doubled the number of keys eight times: 256×28=256×256256 \times 2^8 = 256 \times 256⁠. A key twice as long holds not twice as many keys, but the old number of keys squared.

    Hint

    Each extra bit doubles the number of keys. How many bits were added?

    Worked solution

    1. Each bit has two possibilities, 00⁠ or 11⁠.
    2. For 1616⁠ bits: 2×2×⋯×22 \times 2 \times \dots \times 2⁠, sixteen times, that is 2162^{16}⁠.
    3. 216=28×28=256×256=65 5362^{16} = 2^8 \times 2^8 = 256 \times 256 = 65\,536⁠.

    If you answered 512512⁠, you doubled once, as if a key twice as long held twice as many keys. If you answered 3232⁠, you multiplied 16×216 \times 2⁠.

  3. Step 3 of 6

    Open this step

    One more byte

    Practice · Predict, then look

    Question

    Key size is 5656⁠ bits, like DES’s from 1977, and Eve’s machine tries every key in about twenty hours. Now the key will grow to 6464⁠ bits. How many times longer will Eve need?

    Correct answer

    • Correct 256256⁠ times

    Setup, choices and feedback

    The Scene at this step

    Key size
    56 bitsfixed
    Unlock step by step
    Locked messagefixed

    Choices

    Once the prediction is locked in, the Scene changes

    Key size
    64 bitsfixed

    The Scene then shows: 0.5845 · The same in years of 365.25 days/nodes/kx/outputs/yearsToTryAll

    A prediction is never marked as a failure: the learner sees the outcome and the explanation either way.

    Feedback for a right answer

    28=2562^8 = 256⁠ times: from twenty hours to about seven months. Each bit doubles the number of keys and the time, so eight bits, one byte, multiply it by 256256⁠. In 1998 a purpose-built machine found a DES key in under three days, which is why much longer keys are used today.

    Hint

    Each bit doubles the number of keys. What do eight bits do?

    Worked solution

    1. At 5656⁠ bits there are 2562^{56}⁠ keys, and at 6464⁠ bits 2642^{64}⁠.
    2. The ratio: 264256=28=256\tfrac{2^{64}}{2^{56}} = 2^{8} = 256⁠.
    3. At the same rate of trying, the time grows 256256⁠ times: from about twenty hours to about 0.580.58⁠ years.

    If you chose 1.141.14⁠ or 88⁠ times, you thought the number of keys grows in the same ratio as the key’s length. It doubles for every bit.

  4. Step 4 of 6

    Open this step

    Eight more bits

    Practice · Predict, then look

    Question

    Key size is 4040⁠ bits, and Eve’s machine, trying 101210^{12}⁠ keys a second, goes through them all in about 1.11.1⁠ seconds. How long will a 4848⁠-bit key take it? Write it in seconds.

    Correct answer

    281.5 s ± 5%

    A number prediction counts as right within ± 5%

    Setup, choices and feedback

    The Scene at this step

    Key size
    40 bitsfixed
    Unlock step by step
    Locked messagefixed

    Once the prediction is locked in, the Scene changes

    Key size
    48 bitsfixed

    The Scene then shows: 281.5 s · Seconds Eve needs to try every key at guessRate keys a second/nodes/kx/outputs/secondsToTryAll

    A prediction is never marked as a failure: the learner sees the outcome and the explanation either way.

    Feedback for a right answer

    1.1×256≈2811.1 \times 256 \approx 281⁠ seconds, a little under five minutes. Or directly: 2481012≈2.8×10141012=281\tfrac{2^{48}}{10^{12}} \approx \tfrac{2.8 \times 10^{14}}{10^{12}} = 281⁠.

    Feedback for a wrong answer

    Multiply the 1.11.1⁠ seconds for 4040⁠ bits by the number of times the key count grew.

    Hint

    Eight more bits: 28=2562^8 = 256⁠ times as many keys.

    Worked solution

    1. From 4040⁠ to 4848⁠ bits, 88⁠ bits are added, and the number of keys grows 28=2562^8 = 256⁠ times.
    2. The rate does not change, so the time grows 256256⁠ times too.
    3. 1.0995×256≈281.51.0995 \times 256 \approx 281.5⁠ seconds.

    If you wrote about 1.31.3⁠ seconds, you grew the time in the same ratio as the key’s length, 4840\tfrac{48}{40}⁠.

  5. Step 5 of 6

    Open this step

    Out of reach

    Practice · Reach the target

    Question

    Change Key size until Eve’s machine needs about seven months, 0.580.58⁠ years, to try every key, then press Check.

    Goal

    • 0.58 ± 5%

      At the start of the step: 10780000000000000000

    Setup, choices and feedback

    The Scene at this step

    Key size
    128 bits
    Unlock step by step
    Locked messagefixed
    Read from the Scene at
    The same in years of 365.25 days/nodes/kx/outputs/yearsToTryAll

    One setting that reaches it

    Key size
    64 bits

    Feedback for a right answer

    6464⁠ bits: 2641012≈1.8×107\tfrac{2^{64}}{10^{12}} \approx 1.8 \times 10^7⁠ seconds, about seven months. Eight bits fewer and it is twenty hours; eight bits more, 7272⁠, and it is already about a hundred and fifty years.

    Feedback for a wrong answer

    Not yet. Watch the time on Eve’s board, and change the key size a byte at a time.

    Hint

    A year is about 3.2×1073.2 \times 10^7⁠ seconds. How many keys does the machine try in seven months?

    Worked solution

    1. Seven months is about 0.58×3.16×107≈1.8×1070.58 \times 3.16 \times 10^7 \approx 1.8 \times 10^7⁠ seconds.
    2. At 101210^{12}⁠ keys a second, that is about 1.8×10191.8 \times 10^{19}⁠ keys.
    3. 264≈1.8×10192^{64} \approx 1.8 \times 10^{19}⁠.
    4. Set Key size to 6464⁠ bits.
  6. Step 6 of 6

    Open this step

    Twice as long

    Practice · Choose

    Question

    A 256256⁠-bit key is twice as long as a 128128⁠-bit key. How many times as many keys does it have?

    Correct answer

    • Correct 21282^{128}⁠ times, about 3.4×10383.4 \times 10^{38}⁠

    Setup, choices and feedback

    The Scene at this step

    Key size
    128 bits
    Unlock step by step
    Locked message

    Choices

    Shown in a random order.

    Feedback for a right answer

    22562128=2128\tfrac{2^{256}}{2^{128}} = 2^{128}⁠. A 128128⁠-bit key already takes Eve’s machine a billion times the age of the universe. A 256256⁠-bit key multiplies that another 3.4×10383.4 \times 10^{38}⁠ times. Guessing the key is no way to break good encryption; what threatens it is a weakness in the method itself.

    Hint

    22562128=?\tfrac{2^{256}}{2^{128}} = ?⁠

    Worked solution

    1. At 128128⁠ bits there are 21282^{128}⁠ keys, and at 256256⁠ bits 22562^{256}⁠.
    2. The ratio: 22562128=2256−128=2128\tfrac{2^{256}}{2^{128}} = 2^{256 - 128} = 2^{128}⁠.
    3. 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38}⁠.

    Doubling a key’s length squares the number of keys: 2256=(2128)22^{256} = \left(2^{128}\right)^2⁠.

Lesson 4 of 4 · About 30 minutes

The Diffie–Hellman key exchange

How two strangers agree on a secret key over a channel everyone can hear: mixing paint, the same idea in modular arithmetic, and why Eve cannot work out the key herself.

Open the lesson

The 6 steps and their answers
  1. Step 1 of 6

    Open this step

    Mixing paint

    Practice · Choose

    Question

    Alice and Bob have never met and share no secret at all. They can talk only through the open tube, and Eve copies everything in it. Can they agree on a shared secret colour?

    Correct answer

    • Correct Yes: each mixes a secret colour of their own into the public one, sends the mixture, and adds their secret to what they receive

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6hidden
    Bob's secret
    15hidden
    Locked message / The maths
    Mixing paintfixed

    Choices

    Shown in a random order.

    • Correct Yes: each mixes a secret colour of their own into the public one, sends the mixture, and adds their secret to what they receive

    • Wrong No: first they must meet, or send the secret by courier

      Misconception: Thinks two parties can only agree on a secret key if some secret has already passed between them, in advance or down the channel.

      Feedback from the catalogue

      Everyone thought so until 1976, when Diffie and Hellman showed it is not true. In their key exchange no secret passes down the channel: each side keeps its secret, aa⁠ or bb⁠, and sends only ga mod pg^a \bmod p⁠ or gb mod pg^b \bmod p⁠. Each side combines the value it received with its own secret, and both reach the same ss⁠. Eve sees everything that passes, and still has no fast way to reach ss⁠.

    • Wrong Yes, if each sends their secret colour fast enough

      Feedback

      Speed does not help: Eve copies every capsule, and a secret colour that goes down the tube is no longer secret.

    Feedback for a right answer

    Yes. Only mixtures of the public colour with a secret pass through the tube, and the secrets themselves stay at home. Each side adds its secret to the mixture it received, and both reach the same colour: public, Alice’s secret and Bob’s secret, in any order. Eve can only mix the two mixtures, which gives a colour with too much yellow.

    Hint

    Watch what passes through the tube in the Scene: does a secret colour ever pass through it?

    Worked solution

    1. A public colour is known to everyone, Eve included.
    2. Alice sends public + her secret; Bob sends public + his secret. The secrets are not sent.
    3. Alice adds her secret to what she got from Bob, and Bob adds his to what he got from Alice.
    4. Both sides now hold public + Alice’s secret + Bob’s secret: the same colour.
    5. Eve holds two mixtures, and paint cannot be unmixed.

    If you answered that they must meet, that was everyone’s assumption until 1976.

  2. Step 2 of 6

    Open this step

    From paint to numbers

    Practice · Calculate

    Question

    Now in numbers. The public values: p=23p = 23⁠ and g=5g = 5⁠. Alice’s secret is a=6a = 6⁠. What does she send, A=56 mod 23A = 5^6 \bmod 23⁠?

    Correct answer

    8 ± 0.1

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6fixed
    Bob's secret
    15fixed
    Locked message / The maths
    Mixing paintfixed
    Accepted within
    ± 0.1
    Computed from the Scene at this step’s setting
    What Alice sends, A = gᵃ mod p/nodes/kx/outputs/alicePublic

    Wrong answers it recognises

    • 30 ± 0.1

      Misconception: Multiplies the base by the exponent (5 × 6) instead of raising it to that power (5⁶).

      Feedback from the catalogue

      gag^a⁠ means multiplying gg⁠ by itself aa⁠ times, not multiplying gg⁠ by aa⁠. 53=5×5×5=1255^3 = 5 \times 5 \times 5 = 125⁠, not 5×3=155 \times 3 = 15⁠. Mod pp⁠ you do it step by step: each power is the one before times gg⁠, then the remainder. From 52 mod 23=25^2 \bmod 23 = 2⁠ you get 53 mod 23=2×5=105^3 \bmod 23 = 2 \times 5 = 10⁠.

    • 15630 ± 0.1

      Misconception: Forgets to wrap round: gives the plain result instead of its remainder mod n.

      Feedback from the catalogue

      In modular arithmetic every result wraps back onto the clock: after n−1n - 1⁠ comes 00⁠. Nine o’clock plus 88⁠ hours is not 1717⁠ on a 1212⁠-hour clock, but 17 mod 12=517 \bmod 12 = 5⁠. Powers too: 52=255^2 = 25⁠, but 52 mod 23=25^2 \bmod 23 = 2⁠. After each calculation, divide by nn⁠ and keep only the remainder.

    • 679 ± 0.1

      Misconception: Gives the quotient of the division (how many times it goes in) instead of the remainder.

      Feedback from the catalogue

      “a mod na \bmod n⁠” is the remainder when aa⁠ is divided by nn⁠, not the result of the division. In 17÷517 \div 5⁠ five goes in 33⁠ times, 3×5=153 \times 5 = 15⁠, and 22⁠ is left: so 17 mod 5=217 \bmod 5 = 2⁠. The remainder is always between 00⁠ and n−1n - 1⁠, like a place on a clock with nn⁠ places.

    Feedback for a right answer

    A=8A = 8⁠. A short way: 56=(52)35^6 = (5^2)^3⁠, and 52 mod 23=25^2 \bmod 23 = 2⁠, so 56 mod 23=23=85^6 \bmod 23 = 2^3 = 8⁠. Alice sends 88⁠ down the tube, and Eve copies it. The 66⁠ she sends to nobody.

    Hint

    Climb the powers step by step, taking the remainder after each multiplication: 52 mod 23=25^2 \bmod 23 = 2⁠, 53 mod 23=105^3 \bmod 23 = 10⁠, 54 mod 23=45^4 \bmod 23 = 4⁠…

    Worked solution

    1. 52=255^2 = 25⁠, and 25 mod 23=225 \bmod 23 = 2⁠.
    2. 56=(52)35^6 = (5^2)^3⁠, so 56 mod 23=23 mod 235^6 \bmod 23 = 2^3 \bmod 23⁠.
    3. 23=82^3 = 8⁠, less than 2323⁠.
    4. A=8A = 8⁠.

    Or directly: 56=15 625=679×23+85^6 = 15\,625 = 679 \times 23 + 8⁠. If you answered 3030⁠, you multiplied 5×65 \times 6⁠. If you answered 15 62515\,625⁠, you did not take the remainder, and if 679679⁠, you gave the result of the division.

  3. Step 3 of 6

    Open this step

    Alice's key

    Practice · Calculate

    Question

    Bob’s secret is b=15b = 15⁠, and he sent B=19B = 19⁠. Alice combines it with her own secret, a=6a = 6⁠. What is her shared key, s=196 mod 23s = 19^6 \bmod 23⁠?

    Correct answer

    2 ± 0.1

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6fixed
    Bob's secret
    15fixed
    Locked message / The maths
    Mixing paintfixed
    Accepted within
    ± 0.1
    Computed from the Scene at this step’s setting
    The shared key s = Bᵃ mod p = Aᵇ mod p/nodes/kx/outputs/sharedSecret

    Wrong answers it recognises

    • 22 ± 0.1

      Misconception: Multiplies the base by the exponent (5 × 6) instead of raising it to that power (5⁶).

      Feedback from the catalogue

      gag^a⁠ means multiplying gg⁠ by itself aa⁠ times, not multiplying gg⁠ by aa⁠. 53=5×5×5=1255^3 = 5 \times 5 \times 5 = 125⁠, not 5×3=155 \times 3 = 15⁠. Mod pp⁠ you do it step by step: each power is the one before times gg⁠, then the remainder. From 52 mod 23=25^2 \bmod 23 = 2⁠ you get 53 mod 23=2×5=105^3 \bmod 23 = 2 \times 5 = 10⁠.

    • 47050000 ± 1

      Misconception: Forgets to wrap round: gives the plain result instead of its remainder mod n.

      Feedback from the catalogue

      In modular arithmetic every result wraps back onto the clock: after n−1n - 1⁠ comes 00⁠. Nine o’clock plus 88⁠ hours is not 1717⁠ on a 1212⁠-hour clock, but 17 mod 12=517 \bmod 12 = 5⁠. Powers too: 52=255^2 = 25⁠, but 52 mod 23=25^2 \bmod 23 = 2⁠. After each calculation, divide by nn⁠ and keep only the remainder.

    • 14 ± 0.1

      Misconception: Thinks the shared key can be worked out directly from the public values, for example as A × B mod p.

      Feedback from the catalogue

      The shared secret is s=gab mod ps = g^{ab} \bmod p⁠: reaching it takes aa⁠ or bb⁠. From the public values you can only make combinations such as A×B=ga+bA \times B = g^{a+b}⁠, with the sum of the exponents, not their product. Here A×B mod 23=8×19 mod 23=14A \times B \bmod 23 = 8 \times 19 \bmod 23 = 14⁠, not 22⁠. To find aa⁠ from AA⁠, Eve must solve the discrete logarithm problem, and no fast way to do that is known.

    Feedback for a right answer

    s=2s = 2⁠. 192 mod 23=1619^2 \bmod 23 = 16⁠, 194 mod 23=162 mod 23=256 mod 23=319^4 \bmod 23 = 16^2 \bmod 23 = 256 \bmod 23 = 3⁠, and 196 mod 23=3×16 mod 23=48 mod 23=219^6 \bmod 23 = 3 \times 16 \bmod 23 = 48 \bmod 23 = 2⁠. That is the key Alice will lock her messages with.

    Hint

    192=36119^2 = 361⁠, and 361 mod 23=16361 \bmod 23 = 16⁠. Now 194=(192)219^4 = (19^2)^2⁠, and 196=194×19219^6 = 19^4 \times 19^2⁠.

    Worked solution

    1. 192=361=15×23+1619^2 = 361 = 15 \times 23 + 16⁠, so 192 mod 23=1619^2 \bmod 23 = 16⁠.
    2. 194 mod 23=162 mod 23=256 mod 23=319^4 \bmod 23 = 16^2 \bmod 23 = 256 \bmod 23 = 3⁠, because 256=11×23+3256 = 11 \times 23 + 3⁠.
    3. 196=194×19219^6 = 19^4 \times 19^2⁠, so 196 mod 23=3×16 mod 23=48 mod 23=219^6 \bmod 23 = 3 \times 16 \bmod 23 = 48 \bmod 23 = 2⁠.
    4. s=2s = 2⁠.

    If you answered 2222⁠, you multiplied 19×619 \times 6⁠ instead of raising to the power. If you answered 1414⁠, you multiplied the two public values, 8×198 \times 19⁠: Eve can do that too, and it is not the key.

  4. Step 4 of 6

    Open this step

    Bob's key

    Practice · Predict, then look

    Question

    Bob got A=8A = 8⁠ from Alice, and combines it with his own secret: he works out 815 mod 238^{15} \bmod 23⁠. What will he get? Choose, and then Look inside moves to The maths.

    Correct answer

    • Correct 22⁠, the same key as Alice’s

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6fixed
    Bob's secret
    15fixed
    Locked message / The maths
    Mixing paintfixed

    Choices

    • Correct 22⁠, the same key as Alice’s

    • Wrong A different number, because each used a different secret

      Feedback

      Each did use a different secret, but each got the other secret from the other side, wrapped inside AA⁠ or BB⁠. Both sides end up with gg⁠ raised to aa⁠ and to bb⁠.

    • Wrong 1919⁠, the number Bob himself sent

      Feedback

      1919⁠ is 515 mod 235^{15} \bmod 23⁠: Bob’s secret alone. 8158^{15}⁠ also holds Alice’s secret, because 8=56 mod 238 = 5^6 \bmod 23⁠.

    Once the prediction is locked in, the Scene changes

    Locked message / The maths
    The mathsfixed

    The Scene then shows: 2 · The shared key s = Bᵃ mod p = Aᵇ mod p/nodes/kx/outputs/sharedSecret

    A prediction is never marked as a failure: the learner sees the outcome and the explanation either way.

    Feedback for a right answer

    22⁠, exactly like Alice. Ab=(ga)b=gabA^b = (g^a)^b = g^{ab}⁠ and Ba=(gb)a=gabB^a = (g^b)^a = g^{ab}⁠: both sides work out 590 mod 235^{90} \bmod 23⁠, each in its own way. That is the whole trick of Diffie and Hellman, from 1976.

    Hint

    8=56 mod 238 = 5^6 \bmod 23⁠, so 815 mod 23=56×15 mod 238^{15} \bmod 23 = 5^{6 \times 15} \bmod 23⁠. And what is 196 mod 2319^6 \bmod 23⁠?

    Worked solution

    1. A=56 mod 23A = 5^6 \bmod 23⁠, so A15 mod 23=56×15 mod 23=590 mod 23A^{15} \bmod 23 = 5^{6 \times 15} \bmod 23 = 5^{90} \bmod 23⁠.
    2. B=515 mod 23B = 5^{15} \bmod 23⁠, so B6 mod 23=515×6 mod 23=590 mod 23B^{6} \bmod 23 = 5^{15 \times 6} \bmod 23 = 5^{90} \bmod 23⁠.
    3. The same number: s=2s = 2⁠.
    4. You can check: 522 mod 23=15^{22} \bmod 23 = 1⁠, and 90=4×22+290 = 4 \times 22 + 2⁠, so 590 mod 23=52 mod 23=25^{90} \bmod 23 = 5^2 \bmod 23 = 2⁠.
  5. Step 6 of 6

    Open this step

    Public and secret

    Practice · Choose

    Question

    Eve has copied g=5g = 5⁠, p=23p = 23⁠, A=8A = 8⁠ and B=19B = 19⁠. What else does she need to work out the shared key ss⁠?

    Correct answer

    • Correct aa⁠ or bb⁠: she has to solve 5x mod 23=85^x \bmod 23 = 8⁠ or 5x mod 23=195^x \bmod 23 = 19⁠

    Setup, choices and feedback

    The Scene at this step

    Alice's secret
    6
    Bob's secret
    15
    Locked message / The maths
    The maths

    Choices

    Shown in a random order.

    • Correct aa⁠ or bb⁠: she has to solve 5x mod 23=85^x \bmod 23 = 8⁠ or 5x mod 23=195^x \bmod 23 = 19⁠

    • Wrong Nothing: s=A×B mod ps = A \times B \bmod p⁠

      Misconception: Thinks the shared key can be worked out directly from the public values, for example as A × B mod p.

      Feedback from the catalogue

      The shared secret is s=gab mod ps = g^{ab} \bmod p⁠: reaching it takes aa⁠ or bb⁠. From the public values you can only make combinations such as A×B=ga+bA \times B = g^{a+b}⁠, with the sum of the exponents, not their product. Here A×B mod 23=8×19 mod 23=14A \times B \bmod 23 = 8 \times 19 \bmod 23 = 14⁠, not 22⁠. To find aa⁠ from AA⁠, Eve must solve the discrete logarithm problem, and no fast way to do that is known.

    • Wrong Both aa⁠ and bb⁠

      Feedback

      One of them is enough: with aa⁠ Eve works out Ba mod pB^a \bmod p⁠, exactly as Alice does, and with bb⁠ she works out Ab mod pA^b \bmod p⁠, as Bob does.

    Feedback for a right answer

    She needs one of the secrets. A×B=ga×gb=ga+bA \times B = g^{a} \times g^{b} = g^{a+b}⁠, with the sum of the exponents, not gabg^{ab}⁠: here 8×19 mod 23=148 \times 19 \bmod 23 = 14⁠, not 22⁠. To extract aa⁠ from AA⁠ she has to solve a discrete logarithm, and that is the hard part.

    Hint

    s=gab mod ps = g^{ab} \bmod p⁠. What can Eve get from AA⁠ and BB⁠ without knowing the exponents?

    Worked solution

    1. The shared key: s=gab mod ps = g^{ab} \bmod p⁠.
    2. From the public values Eve can work out combinations such as A×B mod p=ga+b mod p=14A \times B \bmod p = g^{a+b} \bmod p = 14⁠, but not gabg^{ab}⁠.
    3. If she finds aa⁠, she works out Ba mod p=sB^a \bmod p = s⁠. If she finds bb⁠, she works out Ab mod p=sA^b \bmod p = s⁠.
    4. So she needs aa⁠ or bb⁠, that is to solve 5x mod 23=85^x \bmod 23 = 8⁠ or 5x mod 23=195^x \bmod 23 = 19⁠.

Across the unit · 10 misconceptions

Misconception catalogue

Each common mistake this unit recognises, in a few words. Open one for what the learner reads when an answer matches it, and where it is asked.

  • Gives the quotient of the division (how many times it goes in) instead of the remainder.

    The learner reads

    “a mod na \bmod n⁠” is the remainder when aa⁠ is divided by nn⁠, not the result of the division. In 17÷517 \div 5⁠ five goes in 33⁠ times, 3×5=153 \times 5 = 15⁠, and 22⁠ is left: so 17 mod 5=217 \bmod 5 = 2⁠. The remainder is always between 00⁠ and n−1n - 1⁠, like a place on a clock with nn⁠ places.

  • Forgets to wrap round: gives the plain result instead of its remainder mod n.

    The learner reads

    In modular arithmetic every result wraps back onto the clock: after n−1n - 1⁠ comes 00⁠. Nine o’clock plus 88⁠ hours is not 1717⁠ on a 1212⁠-hour clock, but 17 mod 12=517 \bmod 12 = 5⁠. Powers too: 52=255^2 = 25⁠, but 52 mod 23=25^2 \bmod 23 = 2⁠. After each calculation, divide by nn⁠ and keep only the remainder.

  • Multiplies the base by the exponent (5 × 6) instead of raising it to that power (5⁶).

    The learner reads

    gag^a⁠ means multiplying gg⁠ by itself aa⁠ times, not multiplying gg⁠ by aa⁠. 53=5×5×5=1255^3 = 5 \times 5 \times 5 = 125⁠, not 5×3=155 \times 3 = 15⁠. Mod pp⁠ you do it step by step: each power is the one before times gg⁠, then the remainder. From 52 mod 23=25^2 \bmod 23 = 2⁠ you get 53 mod 23=2×5=105^3 \bmod 23 = 2 \times 5 = 10⁠.

  • Counts 1 as a prime number.

    The learner reads

    A prime is a whole number with exactly two divisors: 11⁠ and itself. 11⁠ has only one divisor, so it is neither prime nor composite. The definition was chosen so that every number has only one way to be written as a product of primes: if 11⁠ were prime, you could write 6=2×3=1×2×36 = 2 \times 3 = 1 \times 2 \times 3⁠ and in endless other ways.

  • Takes an odd number that has no obvious small factor, such as 51, 91 or 99, to be prime.

    The learner reads

    An odd number is not divisible by 22⁠, but it can be divisible by 33⁠, 77⁠ or any other prime. 51=3×1751 = 3 \times 17⁠, 91=7×1391 = 7 \times 13⁠ and 99=9×1199 = 9 \times 11⁠. To know a number is prime, check that no prime up to its square root divides it: for 9191⁠, check 22⁠, 33⁠, 55⁠ and 77⁠, and 77⁠ divides it.

  • Thinks the sieve must cross out multiples of every prime up to the count, not just of the primes up to its square root.

    The learner reads

    A composite number up to nn⁠ always has a prime factor no bigger than n\sqrt{n}⁠: if both its factors were bigger than n\sqrt{n}⁠, their product would be bigger than nn⁠. So once the sieve has run through the primes up to n\sqrt{n}⁠, every composite has been crossed out. Up to 400400⁠, 400=20\sqrt{400} = 20⁠, and eight primes are enough: 22⁠ to 1919⁠.

  • Thinks primes keep the same share of the numbers however far you count, as the quarter below 100.

    The learner reads

    The primes thin out. Up to 100100⁠ there are 2525⁠, a quarter of the numbers; up to 10001000⁠ there are 168168⁠, under a sixth; up to 10 00010\,000⁠ there are 12291229⁠, about an eighth. The bigger a number, the more smaller primes there are that might divide it. The chance that a number near nn⁠ is prime is about 1ln⁡n\tfrac{1}{\ln n}⁠, which shrinks slowly. And still they never run out: Euclid proved there are infinitely many primes.

  • Thinks the number of keys grows in step with the key's length, doubling when the length doubles, instead of doubling with every bit added.

    The learner reads

    An nn⁠-bit key has 2n2^n⁠ values, because each bit doubles the number of possibilities. A key eight bits longer does not hold eight more keys, nor 6456\tfrac{64}{56}⁠ times as many, but 28=2562^8 = 256⁠ times as many. And a key twice as long, 256256⁠ bits instead of 128128⁠, holds not twice as many keys but 21282^{128}⁠ times as many. That is why keys only a little longer put guessing out of all reach.

  • Thinks two parties can only agree on a secret key if some secret has already passed between them, in advance or down the channel.

    The learner reads

    Everyone thought so until 1976, when Diffie and Hellman showed it is not true. In their key exchange no secret passes down the channel: each side keeps its secret, aa⁠ or bb⁠, and sends only ga mod pg^a \bmod p⁠ or gb mod pg^b \bmod p⁠. Each side combines the value it received with its own secret, and both reach the same ss⁠. Eve sees everything that passes, and still has no fast way to reach ss⁠.

  • Thinks the shared key can be worked out directly from the public values, for example as A × B mod p.

    The learner reads

    The shared secret is s=gab mod ps = g^{ab} \bmod p⁠: reaching it takes aa⁠ or bb⁠. From the public values you can only make combinations such as A×B=ga+bA \times B = g^{a+b}⁠, with the sum of the exponents, not their product. Here A×B mod 23=8×19 mod 23=14A \times B \bmod 23 = 8 \times 19 \bmod 23 = 14⁠, not 22⁠. To find aa⁠ from AA⁠, Eve must solve the discrete logarithm problem, and no fast way to do that is known.

Index