ModularArithmetic_MathsUnboxed_Handout
ModularArithmetic_MathsUnboxed_Handout
com/mathsunboxed
www.instagram.com/maths_unboxed
Introduction [email protected]
Different ways to think about modular arithmetic: What is 5 (mod 3)?
Proof of 2:
Try this for yourself first by adapting the proof above! If you get stuck, the proof is at the bottom of the next page.
Examples of using Modular Arithmetic: (There are video explanations to these on my YouTube channel)
1. What is the final digit of 7100?
• This is the same as asking “what is 7100 mod 10?”. Have a think about why!
• Note that 7100 = 7 x 7 x 7 x ……. x 7. We want to use Useful Property 2 to help, but 7 is already reduced under
modulo 10. 100 times
How to send secret messages using Modular Arithmetic (the RSA algorithm)
Say you are Person A and you want Person B to send you a top secret A B C D E F G H I
message that can’t be decoded if it is intercepted by someone else.
1 2 3 4 5 6 7 8 9
Person A
1. Choose 2 distinct prime numbers p, q (each greater than 40 and less than 200)
2. Calculate n = p x q
3. Calculate t = (p-1)(q-1)
4. Choose a prime number e such that the highest common factor of e and t is 1.
5. On the website WolframAlpha search “What is the multiplicative inverse of e modulo t?”. Call the result
d. (your search on WolframAlpha has found the multiplicative inverse of e (mod t) which is the number d such
that ed ≡ 1 (mod t). Search up ‘multiplicative inverses modular arithmetic’ for more information on these
numbers. If you’re interested in how WolframAlpha calculates this, search up the ‘Euclidean Algorithm’.
6. Give Person B the values of n and e – in fact everyone can see this! Even the people who you don’t want
to read your future message can get these values; these values won’t help them!
Person B
1. Choose a message that is 3 letters long using the letters A through to I. (you can send longer messages if
you send them in 3 letter chunks. You can also use different letters if you create a table assigning 9 letters of
your choice the numbers 1-9.)
2. Convert your message into numbers using the yellow table above. This is M. Eg. If your message is ‘CAB’
then M = 312.
3. Calculate Me (mod n) using WolframAlpha (type in the search bar “M^e (mod n)”). Label this number C.
4. Give C to Person A – this is your encrypted message!
Person A
1. Compute Cd (mod n) using WolframAlpha. Convert this to letters using the table to receive the message!
Note, that even if someone intercepted the message C when it passed from Person B to Person A, they would be
unable to decrypt it as they don’t have the value d, and they can’t work it out from the values n and e (if they have
these) due to how hard it is factor numbers if they are a product of two large primes.
This is the method that most computers and large companies use to encrypt and decrypt information securely –
except normally they choose p and q to be of over 1000 digits in length!