 One of the nice things about the hill cipher is that any of the ciphers that we've looked at can be reproduced using an appropriately chosen hill matrix. So for example, if I take a matrix that is the identity matrix but permute the rows in some fashion, what I end up with is a transposition cipher. Now if I take an n by n matrix, this is the fundamental feature of the hill cipher. I get an n gram cipher. If the second component of our column vector of our plain text is 1 and the hill cipher is an upper triangular matrix with lower entry 1, what I get is an affine cipher, although this is kind of useful that I could chainsaw to cut a dinner roll. And then finally, if I take a second invertible matrix, m of the correct size, I can produce a polyalphabetic cipher by using this second matrix as a factor of the matrix that I'm going to be using for the actual encryption. So let's take a look at how these variations work. And so I'll use the cipher text 81721427 and I'll work mod 31. So to form a transposition cipher, what I'm going to do is I'm going to choose an identity matrix and permute the rows in some fashion. So for example, let's say I want to use blocks of 6, so I'll take a 6 by 6 identity matrix and I'll switch the rows around in some fashion, completely arbitrary, doesn't make any difference how I do that, and I end up maybe with something that looks like this. And so I switch the rows around, this first row has become the second row, the second row shows up down here, third row moves to, where it is that, right there, and so on. So the rows of the identity matrix have been switched around. For those of you interested in trivia, this is actually a Sestina transposition. There's a 12th century poetic form that uses this particular permutation. That doesn't really matter, but so I'm going to take the plain text. I'm going to break it into blocks of 6. Well, it is a plain text of length 6. There's my plain text. I'm going to form that into a column vector. I'm going to multiply on the left by the permuted identity matrix. And when I do that, I get my encrypted value, where we see our symbols have been rearranged in some fashion. Oh, what can I do next? Well, I can use the hill cipher as it was intended to be used, which is as a trigram cipher, or as a multigram cipher. If I take an n by n matrix, I'm going to produce an n-gram cipher. So again, if I want to continue to work mod 31, what I'll do is I'll set down a random 3 by 3 matrix. So I have a trigram cipher. I do need to make sure that I have something that's invertible. So I'll throw down a random set of numbers for my matrix entries, and I'll check the determinant of this matrix. So that determinant after all the dust settles is negative 110, but since I'm working mod 31, I do need to reduce that value is 14 mod 31. And because 14 is relatively prime to 31, I know that this matrix H is going to be invertible mod 31. And that's a key requirement because if it's not invertible, I can't use it as a form of encryption. So if I want to encrypt my message, I'm going to break it into 3 by 1 column vectors and multiply again on the left. So here's my first block, 8, 17, 21, that multiplication reduced mod 31. Second block, reduced mod 31 gives me these values. And there's my encrypted value again. And what I'm working with here is an actual trigram cipher. This 8 only becomes a 23 when it's in the first of a 3-symbol sequence where the other symbols are 17 and 21. Now, just as a point of observation, we've been multiplying on the left because, well, that's how we're used to doing things in mathematics. As long as we're consistent, though, we can write, multiply as well. So one advantage is that if we do this multiplication on the right, we can write our plaintext somewhat more naturally as a left to right block. So for example, there's my plaintext, 8, 17, 21, 4, 2, 7, and I'm using a 3 by 3 matrix, so I do have to break this up into blocks of 3. But this time what I'm going to do is I'm going to write it as a block of 3 followed by another block of 3. And this time if I multiply on the right by my hill matrix, then I can do the entire encryption in one go. Incidentally, if you're multiplying on the left, you can do the same thing. We have to write our plaintext as a matrix whose columns correspond to the individual entries of our plaintext. So here, multiplying on the right by the hill matrix, I end up with this as my encrypted value, 25, 26, 15, and so on. Notice that this is different from what we got the last time. Remember previously that first set of symbols 8, 17, 21 became 23, 25, 21. This time, instead of 23, 25, 21, we get 25, 26, 15. So we get a different encipherment. It's still a hill cipher, it's just a different hill cipher. So we can also use the hill cipher if we want to turn this into an affine transformation. So I can do that as follows. First of all, I need to use an invertible upper triangular 2 by 2 matrix. I need to make sure that lower entry is going to be 1. And I need to write my plaintext as a 2 by n matrix where the second row is all ones. So my plaintext 8, 17, 21, 4, 2, 7 becomes the matrix 8, 17, 21, 4, 2, 7, and all ones on that second row. So I'll pick some invertible upper triangular 2 by 2 matrix. For example, this one, I can quick check, determinant of this is going to be 5. So this is invertible mod 31 and I can multiply and I get my encipherment, 16, 30, 19, and so on. And there's my affine transformation. One of the more interesting possibilities is that I could choose a second invertible n by n matrix and that turns the hill cipher into a polyalphabetic cipher. So for example, let's say I take my second matrix 3, 5, 2, 9 and my hill cipher is going to be something like this. As before, I'm going to encrypt this particular block here and it's a 2 by 2 hill matrix. So I need to break the plaintext into blocks of 2 and turn them into column vectors. So that first block of 2, that's going to be 8, 17. And as in the standard hill cipher, I will multiply on the left by my hill matrix and reduce everything. Again, we're still working mod 31 and there's my first bit of the encrypted value. Now I'm going to take the second block, 21, 4, and ordinarily I would multiply that by the hill matrix to produce the encrypted value. And that's where the second matrix comes in handy. I'm going to change the hill matrix by multiplying by that matrix. So what I'm actually encrypting uses this matrix product here. And so when I find that product and reduce mod 31, I get my next set of values. And then finally that third block, 27, I would again, using a classical hill cipher, I multiply that by the hill matrix. But this time I'm going to take that modification matrix and I'll multiply it twice. So here my hill matrix that what I'm actually using is this squared times the original value. So that's a new matrix times the plaintext value. And after all the dust settles, I end up with that as my encrypted value.