 In this lesson, we'll be learning about mechanical ciphers, which are ciphertext generated using actual machines. Now, these became really popular around the early 1900s, early 1800s, kind of at the edge of the industrial revolution, where machining these metal parts that are required to make these devices was really something that was feasible for a lot of people. But we'll see that using machines to make ciphertext is nothing new. It's nothing unique about the 1900s. People have been doing this really since the dawn of cryptography. We've already seen the ciphertext wheel created by Alberti back in the 1400s. And then there's also this device called the PsyTale, first mentioned by some Greek poet back in the seventh century BC as a way to perform a transposition cipher. You can see the little strap that gets wrapped around a specific block of unknown shape and known length. They'd wrap it around and then write down everything on the same face of that kind of hexagon, and that would become your message. And then you had to have the same matching block in order to decipher it on your end. So using tools, using machines to perform an encryption is certainly nothing new in history. But we'll see that this is the first time here in the 1900s where it really starts to advance cryptography to an entirely new level that had not been seen before. Now, one key player in the move to a more mechanical encryption machine was Boris Hagelin, who is a Swedish businessman and inventor who invented these machines that required no electricity. We just call them purely mechanical. And Boris was really one of the first people to make millions of dollars. Historians think he is the first person to make over a million dollars from doing some cryptography work as a private citizen. He was the person who sold the patent to some machines that we'll see in just a moment to the US government during the World War II, and then later to businesses and other governments around the world for performing this more modern mechanized encryption. He started working at a Swedish company, which he eventually were to take over and change the name of that to Crypto AG. And they moved to Switzerland at the start of World War II due to the political conflict going on at the time. Now, an interesting historical piece about Crypto AG is that the CIA, so the US government, secretly bought this company in 1970. That was part of an operation called Operation Rubicon. And what they did is after they owned the company is that they would continue selling machines to all of these governments and diplomats, but they would have a secret backdoor in them so they could read all of the messages that were being sent. This was just discovered recently, so I definitely encourage you to read a little bit more about Operation Rubicon. Really interesting historical components there. The first machine we're gonna take a look at is the C-36 Cypher machine, shown here on the screen. You can see this is a pretty small machine. You can tell kind of by the size of the key lock there, relatively how big it is. So it was meant to be almost small enough to fit into your pocket. We'll see a video of one of these working in just a moment. But the key components on a machine like this are that we have a wheel on the left that will set the plain text on, see a little horizontal metal bar that will point to your plain text letter. There's a rotating lever on the right-hand side that you'll spin to encrypt your message. These wheels that we can see popping through the slots here on the top of the case indicate the current position of the enciphering components. Those only turn once, and they all turn once after each letter that's encrypted. And after your plain text letter is encrypted, it gets printed on this piece of tape over here. There'd normally be a spool of all of this paper tape tucked away inside the machine's casing. Taking off the lid, we can see all of the mechanical pieces. So we have all these gears and wheels. These wheels here are what control the possible length of the period of the key stream. So kind of like how we saw with Visionaire, a short keyword has a very short period when we kind of repeat that over and over. The goal of using these wheels is to take out some of that characterization of the repetition in our key stream and provide more randomness. And by choosing wheels that have 25 and then 23 and then 21, 19, and 17 different positions on them, the instances are all relatively prime with each other. They're least common multiple, meaning when they'll sync back up and have the exact same readout is 3,900,000, 225. So you have to go a long message in order to start reusing your key stream, which is what the point was. Up at the top, we have the cylinder with 25 bars across it. Each bar has the location of what's called a lug. Those are those little metal objects protruding out. And those lugs as they rotate around have the possibility of catching with one of these pins that are on the wheel, which we'll see in just a moment, in order to spin our ciphertext wheel into its final position. That ciphertext wheel is over here on the left. You can see it has kind of a rubber stamp for each of the ciphertext possible letters, and that's how it prints onto the machine. So let's zoom in here on this cage or cylinder of bars. So there are 25 bars here, and we can see the different positions across the bar for those lugs to go. Now, each one of those lugs could line up with a particular wheel, wheel one, two, three, four, or five. And as that lug rotates around, and all of these bars will rotate around for every single letter, as it passes by one of the wheels, if that wheel was set into an active position, and we'll talk what that means in just a second, then the ciphertext wheel will turn one time for that bar. So there's possibilities here, that is as this bar wheels all the way around for to encrypt a letter, it could move your ciphertext wheel 25 spots. Once for each of the bars. But what we'll see is that more common is that it's not going to be exactly 25, it's going to be some number smaller than 25, because not all of the five wheels will always be in the active position. So let's see what determines whether or not one of the five wheels is in an active position. On the zoomed in view of the wheels, you can see that each of them is coated with these pins that can be adjusted so they're sticking out to the left side of the wheel or the right side of the wheel. On the furthest left wheel, you can see a row of inactive pins that are being pointed out where they're being pushed in so they appear flat with the wheel. But if you look where the called out arrow is pointing for the active pin, you can see a small little rectangle protruding from the right hand side of the wheel. Now remember these wheels each turn one spot after each letter is encrypted. So these pins are going to be moving around and around, sometimes with the pin now in the active position and some now with an inactive position. And I believe that those positions are determined about what pin is at the bottom of the wheel. Now when a pin is active, what that means is that the lugs will actually spin our ciphertext wheel for that any lugs that line up with that wheel. And if a pin is inactive, so pushed in, then as the bars go around, none of the lugs that correspond with the inactive pin wheel will actually cause the ciphertext wheel to rotate. So again, if all five pins on the wheels were active, then we'd have 25 spins plus one, that always spins one time, for the one rotation of our bars. But because not all of the pins are usually lined up for in the active position, sometimes we'll get less than 25. Usually we'll get less than 25 spins of the ciphertext wheel. Now there is a slight improvement of this machine as it was sold to the US. The US modified the patent from Boris Hagelin and added a sixth wheel and a 25th, 26th, 27th bar on the rotating cylinder. You could also move around where the lugs are. So this just added some security to the machine, but the principle is the same. It did extend out the period, so how long it took for our keys to start rotating, the key stream to start repeating itself. So a little over 100 million characters could go by before we had the exact same configuration of the key stream. Now we actually have a video of this one in use here. So as you watch it, you can see the case goes up. And then the person here in the video will set the plain text letter on the left hand side using that dial. And then spins that cage of bars all the way around. And you can see that all of the wheels turn after each letter that gets encrypted. And as active and inactive pins decide that as those bars were by, how many spots that ciphertext wheel gets rotated. And then once it's done, it actually prints it out. Now because this is that M209B, not the original machine we were looking at, we can see that it can move the ciphertext wheel up to 28 different rotations. And then yeah, when it's done, it prints it out to the tape for easy reading to be transmitted over the radio or the telegraph or maybe more modern days, you would send that in a message like a text message. So how secure were these ciphertext machines? Well, we were able to figure out after the World War II, which is when these were primarily used by US troops, that only about 10% of the American traffic that was sent over the M206B was actually discovered or decrypted successfully by the German army. 6% of that was from actual crypt analysis. So breaking the message and then 4% was more from espionage, they were able to capture some keys and then just decrypt the messages that way. Normally these messages, if they were intercepted and broken by crypt analysis, it would take between seven to 10 days for them to actually be able to recover that message, which for tactical messages like on the battlefield is usually too long for them to be actually useful when you're done. Although there are some reports that towards the end of the war, the German army and secret recovery unit were able to start breaking these messages in just a matter of a few hours, maybe four to six hours. And that would pose a little bit more threat, but again, if the messages you're sending are really just real-time messages, knowing what they said four hours later, not that big of a deal. So now that we've seen how the mechanical version of this works, let's actually take a look at how the mathematics of the system works in order to insightful the message. So at first we'll start with our plain text like normal and we'll convert that to a numerical value. Notice this particular system uses two for B instead of one for B like we've seen, but mathematically this will be equivalent. And then we'll use the machine to generate our key numbers, which is essentially our running key for this message. Now remember, these key numbers are just determined by the unique configuration of the wheels, the pins, the bars, and the lugs that are set right before we encrypt this message. So a key number of 15 means that there must be a certain number of pins in the right spot so that when all of those bars go by, we get 15 rotations of the ciphertext wheel from where it started, which is the plain text. So if we take our key value and subtract off the plain text value, we'll get our ciphertext value, which will correspond to a ciphertext letter printed to the machine. At their core, and this is very important, these mechanical ciphers are not very different from the vision air ciphers that we've seen in the past. The only difference between this and the vision air is that we're using this mechanical machine to create the key stream of numbers using those wheels, pins, lugs, and bars instead of just using a keyword that we repeat over and over or using a primer keyword in the auto key. Because we're using the machine, we get a much more predictable randomness, which is what we're hoping for. Predictable randomness might sound like an oxymoron, but what I mean by that is that we know we're gonna have the right amount of randomness to secure our message every time as opposed to leaving it up to chance of choosing the right keyword or things like that. The other benefit of using a machine over our vision air cipher is that the machine at the time was really a much faster way to implement this, plus the operator didn't need to know anything about modular arithmetic or mathematics. You could teach them to set up the wheels, the pins, the lugs, and all of that, and then all they had to do was set the letter, turn the crank, and look at what got printed. Now for a while, this was the only way for us to do this type of mechanical encryption, but as electronics started to grow in popularity and sophistication, we started to be able to see these rotor systems, as opposed to the pinwheel systems, which were the purely mechanical ones. These rotor systems were electromechanical, meaning it was a mix of mechanical operation and electrical signals being passed. The most notable one was invented by Arthur Scherbius, who was a German electrical engineer, and he created the Enigma machine, which was very popular by the German military during World War II, but you'll see that this was actually invented much earlier than that. The German Navy actually adopted this in 1926. World War II wasn't starting for at least almost another 10, 15 years down the way. Now this system was housed in this wooden box, and you'll see it had a lot of similar components to the older systems, the purely mechanical systems that Hagelin produced. It's got some wheels up at the top, but the big difference here is instead of setting your plain text letter with a wheel, you can type it like a keyboard. And then these plug board here would swap around some electrical signals that pressing the keys on the keyboards would generate. They would eventually pass through some wireings that are contained inside of these wheels that rotate after each letter. And then the cipher text letter, instead of being printed, gets lit up on this upper half of the keyboard. Opening up the case, we can see that these wheels look very similar to the wheels inside of the Hagelin machines. The big difference is that they contain wiring on the inside. So we can see kind of an exploded view here of each of these wheels, is that an electrical signal gets passed from the right hand side to the left hand side, but it doesn't go straight across the wheel. There's a kind of secret wiring pattern that connects the two halves of the wheel. And when you put them, three of them together, you see we've got a pretty complicated system here. Let's run through it. So we're gonna start by pressing letter Q on the keyboard, which closes some electrical circuit that's powered by a battery. We follow that signal through the system, through an initial kind of stationary wheel called the sticker. And then it enters the wheel number one on the right hand side, and we can see that in red. And if we follow that red signal, it goes from the right hand side of wheel one, out the left hand side of wheel one, and then into the right hand side of wheel two, and out the left hand side, and so on. And then it hits this reflector, which passes the electrical signal back through the wheels in the opposite order. So now we're following the blue lines. So the left hand side of wheel three to the right hand side of wheel three, into the left hand side of wheel two, and so on. Until it comes back out of the wheel system. And then it goes through the sticker, which again is kind of the stationary thing, but that's where the plug board comes in. We can now swap electrical signals from one output to the other. So those plug board that we saw earlier will swap the signal. It should have gone past through the wire that connects to the bulb W. But the swap board is gonna swap it to the signal that goes to the bulb for E, which will now light up. So our Q became an E as ciphertext. However, after we press that button, things kind of reset and we press the next button, all the wheels, well not all, but one of the wheels will rotate, which would potentially also trigger a second wheel and so on. These wheels keep rotating around, not all at the same time. So that's a big difference from the mechanical machine. These go one at a time, almost like the car odometer spins them around until they light up our ciphertext. In order to set up the machine, there was a lot of configuration options, and this is what lends itself to a very secure system, is that there's five wheels, but you only ever use three at a time. So you pick three out of the five, the other two go in on this little wooden box for safe storage. Each wheel can then also have some configuration options. You can change where in the wheel that it trips over the wheel to its adjacent side to spin the one like say in the middle. You can change a little setting on the right hand side wheel to determine when it flips over the one in the middle. So a lot of configuration options there. You can have to plug in all of these plugs. Normally the German military used 10 plugs, so you would swap 10 pairs of letters on using the plug board. And that really lends to a lot of security. Like you can see that number, a total number of configuration options which are the keys. So how do we get to that big number? Well as I mentioned, you have to choose three wheels from the five available, so that's 60 choices there. Two of those wheels can have that ring set up to change the wiring or when the next wheel flips over. That's 676 options there. Then you have to decide where does each wheel start in this configuration? Are you lining them up kind of like 0, 0, 0, or is it 17, 5, 22? There's a lot of different ways you can just set the wheels into the machine before you get started. In fact, over 17,000 of those. So just the choices you have to put your wheels in the machine is over 700 million choices, just to put those wheels in there. And then the plug board adds an incredible amount of complexity to the machine. In fact, over 150 trillion different ways you can plug in those 10 cables. That's kind of crazy. And since you have those choices are independent of each other, the ways that you put the wheels in don't impact the ways that you set up the plug board. The total number of keys we obtain is just the product of those two numbers. So that is a huge possibility that we have here for the key space, which is what made it so difficult for the Allied Forces to crack signals from this machine. Now these are not the only two rotor machines that are out there or mechanical machines. All of these kind of machine type ciphers were very popular starting from about the 1920s, 1930s all the way up until the 1970s or so. Here's a couple other examples in case you wanted to look them up. The two that we looked at were really just kind of field cipher machines, meaning they were meant to be used in the field of battle. But there are much more complicated ones that were used at kind of bases like the Cigaba, the Type X, so the Rens, the Nima, and the Stolba. These are a lot more complicated and therefore a lot more heavy so they didn't really make the trip out into the battlefield, hard to carry around. But check these out, they all use a lot of the same principles of trying to generate a really long pseudo-random key stream that could be used to encrypt messages. And they all have the little quirks and pluses and minuses. But ultimately we reached the end of an era. The last really well-known rotation machine was the HX63. It employed nine rotors, really complicated circuitry within the wheels, keyboard, all of that. But as we see is as we get to the 1960s and 70s, computing power really started to take off. And doing this stuff in software by programming a computer became much more efficient and faster than using these mechanical rotating wheels. But it also started to allow other mathematical operations and complexity to the encryption that a mechanical system just couldn't provide. It seems like the last known message that was sent by one of these rotor machines was in 1983 by the Canadian government. And since then they've really gone out of style. So that's it for our mechanical ciphers. I hope that you realize that the biggest takeaway is that these machines just allow the everyday user to implement a really high tech security, but it's really not mathematically different than the vision air cipher. For every character in the plain text, we need to find a way to generate a pseudo random character in our key stream that can be created both by the message creator and the message decoder. The machines allow a nice predictable, long period key stream to be generated by both sides of the equation.