 In this lesson we'll be taking a look at the rail fence cipher, which is the first cipher that we'll learn how to program in the next couple lessons. The rail fence cipher is a transposition cipher, so as a refresher from our earlier lesson, that means that we're not going to be encrypting these letters or changing them from one plain text letter to a different corresponding cipher text letter. We're going to be jumbling around the letters, but in a predictable way. The rail fence cipher specifies that predictable method that we'll be using to scramble the letters. We'll begin with this plain text word mathematics and begin our rail fence cipher. We take each letter one at a time and we'll start by dividing that into two rails or rows in order to reorganize the letters. So we'll start with the letter M on our top row and we'll write the letter A down below into the second row and then we'll come back up with T to the top row down to the second row for the next letter H and we continue to alternate until we spell out our entire plain text. We'll group the top row or rail together to create M-T-E-A-I-S and we'll do the same for the bottom row to create A-H-M-T-C. We'll take the top row and make it the first part of our cipher text and append on the second row to finish it out. We'll group it down below by letters of five to help disguise the length of our words and any spaces or anything like that and we get the final cipher text of M-T-E-A-I-S-A-H-M-T-C. One variation on the rail fence cipher is to change the number of rows used to create the cipher text. Here we'll keep the same plain text word of mathematics and we'll put M-A-T on the first second and third rows and then we'll zigzag back up H on the second row, E on the first row and back and forth. Like we did in the two row rail fence we'll take the top row to make our first group, the middle row now to become our second group and the bottom row will become our third group. Putting them together in order will give us a cipher text of M-E-I-A-H-M-T-C-T-A-S and we've color coded them to keep track of where they came from. In a rail fence cipher you can see it's pretty flexible depending on the number of rows. We'll indicate the key of this cipher to correspond to those number of rows. You could extend this out to do a rail fence cipher with four rows five rows and so on you just have to keep zigzagging back and forth. Let's talk about how to decipher messages that you might receive that have been encrypted using the rail fence cipher. Here's a cipher text that we've received and we know it was using a two row rail fence cipher but the sender and the receiver of the message have to know the key in order for this process to work. We've counted the number of letters we have 11 of them and we've created basically a skeleton here of our zigzag pattern that we know a two row rail fence cipher would use that had 11 letters. We can start filling up the top row because we know the beginning of our cipher text was from the top row of our encryption scheme from the sender so the top row would go across H-R-Y-O-T until we couldn't put any more letters in the top row. Take the remainder of our cipher text message and put it in the bottom row so let's fill that out. I can see that the top row will hold H-R-Y-O-T-R the bottom row is A-R-P-T-E and when we put those in we can now follow the zigzag pattern to recreate our plain text message H from the top row A from the bottom row R from the top row R from the bottom row and so on until we have our plain text message now what you can clearly see is the name Harry Potter. How would this work for a three row rail fence well it'd be pretty similarly. We take the total number of letters the fact that we know it's a three row rail fence will help us set up our kind of skeleton here or our scaffolding and we can see we'll have three letters that go in the top row five in the middle and three in the bottom and following the zigzag pattern we can reconstruct our plain text message of Taylor Swift. Those are the details for the rail fence cipher I encourage you to see how this might work for rail fence ciphers that use four or five or more rows and in the next lesson we'll start to figure out how we can use the Python programming languages in particular strings in order to recreate this in code.