The common analogy used to describe modular arithmetic is fairly simple. All one has to do is look at an analog clock. For example, if it’s 11 AM and you want to know what time it will be in four hours, we instinctively know the answer is 3 PM. This is modular arithmetic, i.e. 11+4 = 3 mod 12. This is an important concept in the technology driven world we live in. Any time a product is purchased on the internet, cryptography comes into play. The *remainder* of this paper (pun most definitely intended) will describe how ancient modular arithmetic plays a very important role in today’s society.

**History of modular arithmetic**

The first known publication of modular arithmetic was in the 3^{rd} century B.C.E, in the book *Elements*, written by Euclid. Within his book, he not only formalized the fundamentals of arithmetic, but also proved it. In what is known as Euclids Lemma, he states that if a prime number divides the product of two different numbers (x and y), then the prime number must also divide one of the numbers (either x or y), but it could also be both. Between the 3^{rd} and 5^{th} centuries a paper publish by Sun Tzu describes a modular arithmetic process known as the Chinese remainder theorem. This theorem is essentially the basis for modern RSA encryption schemes that are present on every banking/e-commerce website. It uses a congruent set of keys to produce the same numerical value. Imagine if there was a lock on a door that two differently cut keys could unlock and open, this is essentially how Chinese remainder theorem works.

**Modern modular arithmetic**

The modular arithmetic that we use today was discovered by Carl Friedrich Gauss in 1801.

Gauss is famous for numerous discoveries across a wide variety of fields in science and mathematics. Gauss’s proposition, from his book *Disquisitiones Arithmeticae, *defines modular arithmetic by saying that any integer N belongs to a single *residue-class* when divided by a number M. The *residue-class* is represented by the remainder, which can be from 0 to M-1. The remainder is obtained by dividing N by M. Given this fact, Gauss notices that two numbers that differ by a multiple of M are in the same *residue-class.* He then discusses the role of negative numbers in modular arithmetic. The following is an excerpt from his book:

“The *modulus* m is usually positive, but there’s no great difficulty in allowing negative *moduli* (classes modulo m and -m are the same). For a zero modulus, there would be infinitely many residue classes, each containing only one element. [This need not be disallowed.]”

**Modular Arithmetic’s Role Today**

RSA encryption is named after those who invented it, Ron Rivest, Adi Shamir, and Leonard Adleman (RSA is obtained from their last names). RSA is the process by which information can be passed between two parties without another individual being able to intercept the message. Burt Kaliski has been one of the major contributors to RSA encryption since the 1980’s. I would like to start off with a passage from Burt Kaliski’s paper titled “The Mathematics of the RSA Public-Key Cryptosystem”:

“Sensitive data exchanged between a user and a Web site needs to be encrypted to prevent it from being disclosed to or modified by unauthorized parties. The encryption must be done in such a way that decryption is only possible with knowledge of a secret decryption key. The decryption key should only be known by authorized parties.”

This is a high level description of how RSA encryption works. It is also called public-key encryption, because anyone can obtain a copy of the encryption key it is publically available, but the decryption key cannot be obtained. This makes RSA encryption a secure way of passing data between an individual and a web site.

Performing this calculation (encrypting and decrypting text) is fairly simple. With a basic understanding of modular arithmetic it can be accomplished. First a public and private key must be produced by following the steps below:

- Generate large prime numbers, p and q (these should be hundreds of digits)
- Compute the modulus n, n = p×q
- Compute the totient, totient = (p-1)×(q-1)
- Choose an “e” > 1 that is co-prime to the totient
- Choose a “d” such that d×e = 1 mod totient

Once those steps have been completed, a public key (n, e) and a private key (n, d) have been generated. The public key can be distributed to anyone, but the private key must be kept safe. It’s easy to see that without the modular arithmetic this algorithm would be easy to discern. One could generate pairs of random numbers until a pair is found that when multiplied together, would equal the modulus n found in step two above. From there, it would be easy to find all numbers co-prime to the totient in step three. Modular arithmetic then comes into play, because it allows infinite pairs of numbers to satisfy the constraint listed in step five, but it would not allow the user to decrypt the message. In other words, 11+4 = 3 mod 12, but also 11+16 = 3 mod 12. This makes it impossible to determine what the original number was (it could be 4 or it could be 16, or any other multiple of 12).

Once the keys have been generated it is easy to encrypt and decrypt text. To encrypt a message “m,” given the public key (n,e) generated above:

C = m^{e} mod n

“C” is then the encrypted message that gets passed to the other party.

To decrypt the message “C” created above, all that is required is the inverse of the operation to encrypt:

M = c^{d} mod n

Let’s do an example to illustrate the instructions listed above (note: we will be using small prime factors because the math is simpler).

- Select a p and q that are prime
- P = 11
- Q = 3

- The modulus n is then equal to P×Q = 11×3 = 33
- Computing the totient to be equal to (p-1)×(q-1) = (11-1)(3-1) = 20
- To select an “e” we must find a number that is coprime to 20
- The smallest value that is coprime to 20 is 3 because 3 is the smallest number that cannot divide 20 evenly, so “e” = 3

- Now we need to find “d”, d=
*e*^(-1) mod [(*p*-1)×(*q*-1)]- Using the Euclidian Algorithm we get d = 7

Now let’s say we want to encrypt the message “4.” To do this we need to know the public key, which in our case is (n=33, e=3). All we have to do is compute:

C = 4^{3} mod 33 = 31

We can pass 31 (c=31) along to the website, which will then decrypt it using the private key (33, 7):

M = 31^{7} mod 33 = 4

Our message has been successfully “passed” from one place to another.

**Thoughts**

Without the work from previous mathematicians, this process would not be possible. Modular arithmetic plays a crucial role in our everyday lives and we don’t even notice it. I think it’s an amazing mathematical concept and provides a deep insight into the world of number theory. Even today there are computers constantly trying to figure out how to factor large prime numbers without success. I don’t know if RSA encryption will stand the test of time, but for now it’s the best we’ve got.

**References**

http://en.wikipedia.org/wiki/Cryptography#History_of_cryptography_and_cryptanalysis

http://www.britannica.com/EBchecked/topic/920687/modular-arithmetic

http://mathworld.wolfram.com/ChineseRemainderTheorem.html

http://www.numericana.com/answer/modular.htm#modulo

benbraunOne of the most interesting applications, to me, of modular arithmetic is in generating pseudo-random sequences. This is what was at the heart of the NSA hacking scandal during the past 12-18 months. An interesting video about it, featuring Edward Frankel of UC Berkeley, is here: http://www.numberphile.com/videos/NSA1.html

LikeLike