 Remember, the Vernum Cypher allows for perfect secrecy, but it requires a key that's as long as the message, different for every message, and randomly generated, so it's impractical for most purposes. Now, interestingly enough, none of these requirements are what make the Vernum Cypher impractical. The real problem is this. An important challenge in communication security is the key exchange problem, and it comes down to this. If you could communicate the key securely, why not use the same method to communicate the message? With regards to our Vernum Cypher, in order to use the Vernum Cypher, we need a key that's as long as the message we're going to send, so if we can send the key securely, we can also send the message securely. More generally, if we have to transmit the key, then we have to keep in mind the more information you communicate, the less secure your system is. And so this suggests the following idea, rather than transmitting a key, transmit a formula that produces the key. Essentially, rather than sending a cake, we'll send the recipe for a cake. In the context of the Vernum Cypher, we want to construct a function f, where an, given by f of n, is a sequence of random numbers. Well in order to do that, we need to have some idea of what we mean by random, and so we might ask the question, how do we know if our sequence is random? And let's put down a provisional definition. A sequence of numbers is random if the knowledge of the prior terms of the sequence give no insight into the knowledge of the later terms. We can make this idea mathematically rigorous, but we'll do that later. There's just one problem. If we use a function to generate a sequence, the later terms of the sequence are completely determined by the prior terms. And what this means is that no function can produce a random sequence. However, it's possible that we can produce what's known as a pseudo random sequence. Because we're producing it by a function, the output is completely deterministic, but that trace of randomness comes from the fact that it's effectively unpredictable. And in short, we say that we want a pseudo random number generator, PRNG. The middle square method was an early method of producing pseudo random numbers, and it works like this. Begin with a k-digit number, square it to produce a 2k-digit number, and add leading zeros as necessary. And then we'll use the middle k digits as the pseudo random number. And then we'll lather, rinse, repeat. For example, let's start with s equal 34. 34 squared is 1,156, and our two middle digits are 1 and 5, which will be our pseudo random number. We'll take 15 and square it to get 225, and we prepend a zero to give us a four-digit number. The two middle digits are 22, and that'll be our next pseudo random number. And we can continue this. 22 squared is 484, prepended with a leading zero. The middle two digits, 48, are the next pseudo random number, and so on. Unfortunately, the middle square method doesn't produce long sequences of random numbers. So for example, if we start with s equals 34, the sequence we produce is going to be... And the problem here is once we produce 10, 10 squared is 100, and our middle two digits is going to be 10 again. And so this sequence will just keep outputting 10, and this is a fixed point. There are other possibilities. If we start with s equals 57, our sequence is going to alternate between 24 and 57. This is a period two sequence. So remember, our provisional definition of randomness is that we couldn't predict the next term of the sequence based on the preceding terms. And so we might ask, what makes a sequence predictable? And one possibility is repetition. We have a fixed point. So our sequence 15, 22, 48, 30, 90, 10, 10, 10, 10, and so on. We know what the next output's going to be. So if we see 24, 57, 24, 57, 24, we can probably guess that the next output value is going to be 57. Now it's not necessary that we be able to predict exactly what the next output is going to be. As long as we can say something about the next output, that gives us an element of predictability and eliminates some of the randomness. So a somewhat subtle way that a sequence may be predictable is if it exhibits what's called monotonicity. And that's a fancy way of saying if the terms always decrease or always increase. Now for monotonicity, as well as for repetition and periodicity, it's important to keep in mind that we don't really care what happens at the beginning of the sequence. What we care about is the long-term behavior. So maybe our sequence starts at 63, 96, 21, 44, 93, but maybe it settles down after a while, 64, 9, 8, 6, 3. And you'll notice that these last few terms are decreasing. If that behavior keeps up, while we couldn't necessarily predict the next term, we would suspect that it's going to be smaller than 3. Now of these three things that make a sequence predictable, it's hard to avoid repetition and periodicity, but monotonicity is easy to avoid if we work mod n. So let's take a look at that next.