 So, welcome to this screencast where we're going to try to apply the information we've learned about the division algorithm and integer congruence to a classic problem in cryptography. Cryptography is the practice of making coded messages and using mathematics to hide information from unauthorized people. We use cryptography every day. When you make a secure financial transaction on the web or give your password to your email program, your data are being encrypted so that anyone who is lurking around trying to get that information for malicious purposes can't do so. What we're learning here about integer divisibility turns out to be the mathematical foundation of much of how modern encryption systems work. And to get a glimpse of this, let's go all the way back in time to the days of the Romans. In fact, during those times during the Gallic Wars, Julius Caesar, or maybe one of his functionaries came up with this, got the idea of encrypting text messages using a means that I will describe now. I should mention before we do this that this is somewhat different than what Caesar actually did, but it's close enough for an example. So let's take the letters A through Z and convert them into numbers, zero for A, one for B, two for C, and so on and sequence until you get up to 24 for Y and 25 for Z. And here's a list of their numbers and their, the letters and their number equivalents in case you need a reference. So let's suppose you want to send someone a message and take the message and convert all the letters in that message to numbers using our assignment here. So for example, if I want to send the message help, the H corresponds to the number seven, E is the number four, L is 11, and P is 15. Now we're going to choose a positive integer and keep it secret. Let's suppose we pick 950 for our integer. So I'm going to now go through the string of numbers and add that integer to each of my numbers. So my message help, which was translated into the string 7, 4, 11, 15, is now going to say 957, 954, 961, 965. Now you have a bunch of numbers that are kind of big. Here's the last two steps before sending the message. Go through each number and find its least non-negative residue, modulo 26. That's kind of a weird step, but it makes sense when you think about what happens when you reduce a number to its least non-negative residue, mod 26. So for a concept check, what is that? What does happen and why should we reduce all these numbers, mod 26? Is it because 26 is the product of two prime numbers? Is it because the least non-negative residue, mod 26 of any integer, is another integer between 0 and 25? Is it because 26 is half of 52? Or is it because the people of the Romans were fighting didn't really know any math? So the answer here is going to be B. A and C are definitely true but sort of irrelevant and I'm not even sure D is true in the first place. But the main point is that when I take those four numbers in my message and reduce them to their least non-negative residues mod 26, I'm going to get remainders. These are numbers between 0 and 25. That's what the division algorithm tells us. That least non-negative residue of each of those integers is the remainder I get from the division algorithm when I divide by 26. And so their remainders have to be between 0 and 25. Well, why is that important? Well, once I've converted the message to integers between 0 and 25, I can then map them back to letters using the alphabet like so. 957 for example is divided by 26 goes in 36 times with a remainder of 21. And so the least non-negative residue of 957 mod 26 is 21. Likewise, if you take 954 and divide it by 26, it goes in 36 times with a remainder of 18 and that's its least non-negative residue mod 26. Likewise, 961 leads to a remainder of 25 and 965 leads to a remainder of three. So now my message has gone from the letters H-E-L-P to the number string 7, 4, 11, 15 to the number string 957, 954, 961, 965. And now through least non-negative residues to the number string 21, 18, 25, 3. Now to complete the encryption, we're going to assign these to letters in the alphabet using the same method we started out with. 21 gets assigned to V, 18 gets assigned to S, 25 is a Z, and 3 is a D. And so that's my encrypted message, V-S-Z-D. I send that to the person I need to communicate with and anybody intercepting that message will look at it and see the word z-z-du and have no idea what I'm saying, which is the whole point. So I can use the least non-negative residue idea to encrypt a message. Once my intended recipient has the message, presumably she has the same offset number 950 as I do, just like when, if I want to share a locked box with another person, we both have to have the same key to the box to open and lock it. To decrypt, she can just go back through this process backwards. She can translate the letters and the message to numbers, subtract the offset value instead of adding it, and then find the least non-negative residue, mod 26, and then reassign back to letters like you see here. So this kind of cipher is called the shift cipher because what it's doing is shifting each letter in my message forward in the alphabet a number of times equal to that offset value that I chose, 950. But since they are clearly not 950 plus letters in the alphabet, if I shift too far, I just wrap back around to the beginning of the alphabet and keep on shifting. This is a lot like the clock arithmetic we played with earlier in the course. Since I could wrap the alphabet many times around when I do the shifting, I want for the final position of the character to have a number between 0 and 25. I might go around 26 letters hundreds of times, but once I factor out all those complete rotations of 26, I ultimately want just the remainder that's left over and that's my true offset. So the shift cipher is actually trivially easy to break if you think about it because if you capture my message, all you have to do is just try one offset value after the next to decrypt it until you've got some sort of coherent message. But the idea of using integer congruence to construct crypto systems is very common. In fact, I'd say that most modern encryption and secure signature algorithms in use today involve the division algorithm somewhere and some central kind of way. So less we think integer congruence is just an exercise. In fact, it's one of the most heavily applied concepts you now know in your entire mathematical toolbox. So I hope you enjoyed that and thanks for watching.