This course will introduce you to the foundations of modern cryptography, with an eye toward practical applications.

Loading...

From the course by University of Maryland, College Park

Cryptography

348 ratings

University of Maryland, College Park

348 ratings

Course 3 of 5 in the Specialization Cybersecurity

This course will introduce you to the foundations of modern cryptography, with an eye toward practical applications.

From the lesson

Week 1

Introduction to Classical Cryptography

- Jonathan KatzProfessor, University of Maryland, and Director, Maryland Cybersecurity Center

Maryland Cybersecurity Center

[SOUND] In the previous lecture we talked

Â about defining what we mean by secure encryption.

Â And we reached an informal description of the security we were after.

Â Recall that what we said is that we should consider an encryption scheme secure

Â if regardless of any prior information the attacker has about the plaintext,

Â observing a ciphertext should reveal no additional information to

Â the attacker about the plaintext.

Â Remember also that we say we were going to be considering the threat model

Â of a ciphertext only attack, meaning that the attacker only observes ciphertext,

Â passively, but doesn't actively interfere with either the sender or receiver.

Â And that we would be considering the simplest threat model which is that

Â the attacker observes only a single ciphertext.

Â We can adapt our definition to more complicated cases, but

Â this is the one we're going to be considering for now.

Â Now what we want to do in this lecture, is to define this informal definition of

Â security that we have, formally, rigorously and mathematically.

Â To do that we're going to need to start talking about probability and so

Â I just want to go over some very basic concepts in probability that I assume you

Â have encountered before in one form or another before.

Â Again we are not going to need a very formal view of probability.

Â That formal view is, there it's present.

Â We can define everything completely rigorously if we wanted to but

Â I just want to assume here that you seen these concepts before, that you

Â are familiar with them, whether or not you have seen them in their complete rigor.

Â So we're going to use the, terminology of a random variable.

Â Now again, this has a formal definition in probability theory.

Â For our purposes, it's enough to just think of a random variable as a variable

Â that takes on certain values with certain specified probabilities.

Â For our purposes we're only going to be concerned with discrete random variables.

Â That means that there's some finite set of values that the variable can

Â possibly take.

Â And so we don't have to worry actually about taking integrals or

Â about considering continuous parameters or

Â continuous distributions on those random variables.

Â So again, a random variable is just going to be a variable that takes on

Â certain values with some probabilities that we're going to specify.

Â And in particular, a probability distribution for

Â a random variable is going to be a specification of the probabilities

Â with which that variable takes on each possible value.

Â We know that these probabilities must be in the range between 0 and 1 inclusive.

Â And, furthermore, the sum of the probabilities with

Â which the variable takes on all these different values should equal 1, right?

Â The various probabilities should all sum to 1.

Â again, we'll also use the terminology of an event, which is something that has

Â a formal definition within probability theory, but for our purposes,

Â we can just think of, as a particular occurrence, in some randomized experiment.

Â And we'll write probability bracket E, to denote the probability of

Â some particular event E, the probability that some occurrence actually happens.

Â So a typical example of an event that we'll be concerned with

Â is the probability that some random variable takes on some value.

Â We then have the notion of conditional probability which is the probability

Â that one event occurs, assuming that some other event has occurred.

Â And we'll write this as the probability of A Bar B.

Â That is the probability of event A, conditioned on the occurrence of event B.

Â And by definition the probability of A conditioned on

Â B is equal to the probability that both events A and

Â B occur, divided by the probability that event B occurs.

Â We're assuming here that event B occurs with non zero probability so

Â we don't have any division by zero, okay?

Â So this is both an informal definition of what we mean by conditional probability as

Â well as a formal definition of what the notation probability of

Â A conditioned on B actually means.

Â With this definition of conditional probability we can now define formally

Â what it means for two random variables X and Y to be independent.

Â And actually I'll point out here some notation that I'll generally be

Â consistent with which is to use capital letters for random variables and

Â lower case letters for values that those random variables can take.

Â Okay so here we have random variables capital X and capital Y,

Â and we'll say that they're independent, if for all possible values X and

Â Y, the probability that X, takes on the value little x,

Â conditioned on the event, that random variable Y, takes on value lowercase y.

Â Is exactly equal to the probability that random variable X takes on the value X in

Â the first place, i.e.

Â The fact that the random variable Y takes on any particular value is irrelevant as

Â far as determining the probability with which X takes on some particular value.

Â Finally we're going to use in this lecture and some of the examples the law

Â of total probability which is just a very convenient way to break up and

Â therefore calculate the value of some probability.

Â So let's let E1 through EN,

Â be events, that partition the space of all possibilities.

Â This means, that the Ei, are all, pairwise impossible.

Â That means we can't have it be the case that both Ei, and Ej occur for

Â any i and j.

Â So that is if E1 occurs, then it's impossible for E2 to occur also, and

Â if En minus 1 occurs, then it can't be the case that E3 occurs.

Â Okay, so these events are, are pairwise impossible and

Â moreover they partition the space of all possibilities in the sense that at least

Â exactly one of E1 through En have to occur, so some event Ei has to occur.

Â Then for any other event A we can express the probability of event A as

Â the sum over all i of the probabilities that A occurs and also Ei occurs.

Â Right, this completely partitions the possibilities for

Â when A occurs because some Ei has to occur.

Â Exactly one of the Ei's has to occur.

Â And so by summing over the probabilities of A and each of those events Ei,

Â we recover the total probability that event A occurred.

Â And then we can break this up further using our definition of

Â conditional property to be equal to the sum over all i of the probability of

Â A conditioned on event Ei times the probability of event Ei.

Â Think, now again, I do assume that you've seen or

Â encountered all of these concepts before.

Â This was just meant to be a brief review.

Â If you haven't, then I would recommend you look at some

Â introductory probability text.

Â The first chapter or the first chapter and a half perhaps.

Â For more, thorough coverage of these different term, terms and definitions.

Â So let's get back now to cryptography.

Â So remember the formal definition of a private key encryption scheme, okay?

Â A private key encryption scheme is defined by a message base, bold M, all right,

Â that's the set of all possible messages that are allowed to be or that can be

Â encrypted by the scheme, as well as three algorithms, Gen, Enc and Dec.

Â Gen was the key generation algorithm.

Â This is a probabilistic algorithm that generates a key,

Â that Iâ€™ll denote by lower case k.

Â The encryption algorithm takes as input a key k, and a message M,

Â in the message base and outputs some ciphertext E.

Â And just remember that we're allowing the encryption algorithm to

Â be randomized meaning that if you run it several times, even using the same inputs,

Â k and m, you can potentially get different ciphertext out.

Â 'Kay, we haven't seen an example of such a scheme yet, but we're,

Â we're allowing that in our definition.

Â Finally, the decryption algorithm takes as input a key k and

Â a ciphertext c and outputs a message m.

Â And we have the correctness condition that decryption of a ciphertext encrypted,

Â that the encryption is the message, where you encrypt and

Â decrypt using the same key, should recover the original message.

Â Again, I haven't put that on this slide.

Â Now by way of some more notation, I want to define in parallel to

Â the notion of using bold face m for the message space.

Â I want to define the notation of a bold face k to denote the key space.

Â Thatâ€™s just the set of all possible keys, that is the set of

Â all possible things that can be output by the key generation algorithm.

Â We use also a bold face C, for the ciphertext space, that is the set of

Â all possible ciphertexts that can be output by the encryption algorithm,

Â taken over all possible keys that can be output by the key generation algorithm and

Â all possible messages that are in the message space.

Â So now what we want to do is look at probability distributions

Â over the messages that can be sent.

Â So we'll let capital M without the bold face, okay,

Â capital M be a random variable denoting the value of

Â the message that the sender wants to communicate to the receiver.

Â So this is a random variable that can potentially take on values in

Â the entire message space.

Â Right, so a priori, the set of possible values for

Â what the message can be are exactly those values that are in the message space.

Â We're not allowed to encrypt anything outside the message space but

Â we are potentially allowed to encrypt anything we like in the mess,

Â message space.

Â Now, the random variable M is meant to reflect the likelihood of different

Â messages being sent by the parties, and this takes into

Â account anything that the attacker might know about what those messages might be.

Â So this distribution, this random variable, M,

Â over the messages that can be sent is meant to reflect, not only the different

Â probabilities with which the sender might want to transmit a certain message.

Â But also something about, perhaps, the attacker's external knowledge that may

Â have some influence or some bearing over what the sender is sending.

Â So just as a, as a, as one particular example,

Â we might have the following distribution over random variable M,

Â that the probability that the message is equal to attack today Is 0.7 and

Â the probability that the message is don't attack is 0.3.

Â And everything else in the message space has a probability of zero.

Â So the only possibilities are either attack today or

Â don't attack and those are going to occur with respective probability 70% and 30%.

Â Okay, now in other situations of course, it might be different.

Â Maybe again, those are the only two possible messages, but

Â maybe the attacker has no idea whether the sender wants to attack or not.

Â And therefore the probabilities would each be 0.5 or maybe there are some other

Â messages that are possible that can occur with different probability what have you.

Â You're right, you have different possibilities of what those can be, but

Â here we're just fixing some particular distribution for

Â this random variable M as specified, okay?

Â Now we're going to let capital K be a random variable denoting the key.

Â The values that this random variable can take are exactly those in

Â the key space, right?

Â Only those values in the key space are possibilities for the key.

Â And actually any prob, any value in that space is a possible value for the key and

Â so is a possible value that this random variable K can take.

Â Now one important thing is that if we fix the encryption scheme, or

Â fix some encryption scheme, Gen, Enc and Dec, then the key generation algorithm

Â itself defines for you the probability distribution for K, right.

Â The probability that the random variable K, takes on some particular value,

Â lowercase k or

Â the probability that the key is equal to some particular value K is, by definition,

Â equal to the probability that the key generation algorithm outputs that key.

Â The probability that the key generation algorithm outputs the particular key,

Â given by this value lowercase k.

Â So the encryption scheme defines your distribution over the random variable k.

Â Now we're going to make the very crucial and

Â important assumption that the random variables M and K are independent.

Â Right, this means that the probabilities with which the message takes on some value

Â are independent of the probabilities that the key takes on some particular value.

Â Now this is actually a very reasonable assumption,

Â because the messages that a party wants to send to another party should not

Â depend on the key that's used to encrypt that message, right?

Â We imagine that we externally to the encryption scheme,

Â have some message that they want to communicate.

Â And then we're sampling a key and

Â using some encryption scheme to encrypt that message.

Â But the details of the encryption scheme and the particular key we ended up

Â choosing shouldn't influence the message that we're sending.

Â This is a crucial assumption, and one that we're going to make throughout the class.

Â It is possible to concoct scenarios where this assumption doesn't hold.

Â But in that case, the definitions we're giving do not apply, and

Â much more complex definitions need to be considered.

Â But traditionally we, the assumption is made that M and K are independent, and

Â this is the assumption we are going to make here.

Â Moreover, this is the reasonable assumption that should hold except in

Â some very unusual circumstances.

Â So, let's fix some encryption scheme, given by Gen, Enc and

Â Dec, and fix some distribution for the message.

Â Some distribution on capital M on the message that the sender is going to

Â send to the receiver.

Â So we have now fixed by the encryption scheme the distribution over capital K,

Â and we've fixed by assumption a distribution over

Â the message space given by capital M.

Â Consider now the following randomized experiment.

Â What we'll do, is first, chose a message little m,

Â choose a particular message m, according to the given distribution, right?

Â So, going to back to the example before,

Â that means we might pick the message attack now with probability 0.7 and

Â the message don't attack, with probability 0.3.

Â So we sample it according to those probabilities and

Â now we've chosen our message and let's call that little m.

Â We then generate a key, K,

Â using the key generation algorithm, i.e we sample the key k

Â according to probability distribution on the random variable capital K.

Â And then what we're going to do is kind of couple those together

Â by encrypting the message we've chosen using the key that we've chosen, and

Â the encryption algorithm that we're given having fixed the encryption scheme.

Â This gives us a ciphertext that we'll denote by little c.

Â The key point here is that this defines a distribution on the ciphertext, right?

Â This process of sampling a random message, sampling a key and

Â then encrypting the message using that key defines some distribution on

Â the ciphertext, and we can denote the distribution on the random variable

Â that denotes the ciphertext by the variable capital C.

Â 'Kay, so we'll let capital C be the random variable denoting the value

Â that the ciphertext takes on after this experiment.

Â I think it's helpful here to walk through an example of how this works out and

Â do an explicit calculation.

Â So let's consider the shift cipher.

Â We said that the the fixing an encryption scheme defines the distribution over

Â capital K.

Â And indeed in the shift cipher, the key is chosen uniformly from the set of

Â all characters, or from the set of all numbers between 0 and 25, i.e.,

Â the distribution on capital K is the one where the probability that the key

Â takes on, any particular value between 0 and 25, is exactly 1 over 26.

Â Right, every key in the range of 0 to, 0 to 25 is chosen with equal probability.

Â Now let's assume we'll take a simple example of

Â a distribution over the message space.

Â Assume that the probability that the message is the single character a is 0.7,

Â and the probability that the message is the single character z is 0.3.

Â Well, let's calculate now

Â the probability that the ciphertext is the single character b.

Â Well, there are only two possibilities.

Â Either the message is equal to a and the key is equal to 1.

Â Or, in that case we shift our message by one position and indeed get

Â the ciphertext b, or the message is equal to z and the key is equal to 2.

Â Those are the only two ways that we can end up with a ciphertext being equal to

Â the character b.

Â And now we just have to compute these probabilities.

Â So the probability that the ciphertext is equal to the character b is equal to

Â the probability that the message is equal to a and the key is equal to 1,

Â plus the probability that the message is equal to z and the key is equal to 2.

Â Because the message and

Â the key are independent, those become the, just the products of the two terms.

Â So we have the product sorry the, we have the probability that M equals a times

Â the probability of K equalling 1, plus the probability that M is equal to z,

Â times the probability that K is equal to 2.

Â And now we just plug in the known values for those different probabilities.

Â Right, the probability that M, is equal to a, we said was 0.7.

Â The probability that k is equal to 1 is 1 over 26 and

Â the probability that m is equal to z is 0.3.

Â The probability that the key is equal to 2 is 1 over 26.

Â Adding that all together, we see that the total probability with which

Â the ciphertext is equal to the character b is exactly 1 over 26.

Â 'Kay, nothing magical, but just going through the steps,

Â I think clarifies a little what we mean, what we meant on the previous slide.

Â Taking another example, a slightly more complicated one,

Â we'll again consider the shift cipher, but

Â now let's look at a different distribution over the message space.

Â So now we'll assume that we have two possible messages that can be sent,

Â like before, but they're now longer than one character each.

Â So we have that with probability one half, the message is equal to the string O-N-E.

Â And with probability one half, the message is equal to the string T-E-N.

Â Right? One or ten.

Â What's the probability that the ciphertext happens to

Â turn out to be equal to the string rqh?

Â Well, if we break it up as before, what we have is that this is equal to,

Â using the law of total probability, the probability that C is equal to rqh

Â conditioned on M being equal to one, times the probability that M is equal to one,

Â plus the probability that C is equal to rqh conditioned on M being equal to ten,

Â times the probability that M is equal to ten.

Â And we can compute that as follows, so conditioned on the message,

Â being equal to one, the cipher text turns out to be equal to rqh if and

Â only if we have a shift of three i.e.,.

Â the key was equal to three.

Â Right in that case we have o going to r,

Â we have n going to q and we have e mapping to h.

Â So now the probability that the ciphertext is equal to

Â rqh conditioned on the fact that the message is equal to

Â one is exactly the probability that the key is equal to three, which is 1 over 26.

Â We multiply that now by the a priori probability with which

Â the message was equal to one, which we're given as one half, and

Â now we come to a more interesting calculation, right?

Â What's the probability that the ciphertext is rqh conditioned on

Â the message being equal to ten?

Â Well, if you think about it a little bit, or if you try to exhaust over all

Â possible keys, you can see actually that there's no possible way

Â the ciphertext can be equal to rqh, given that the message is equal to ten.

Â And the reason for that is simply that there is no shift that will

Â simultaneously shift t to r, e to q, and n to h.

Â There's just no way for that to happen.

Â So the probability that the ciphertext is equal to rqh

Â conditioned on M being equal to ten is 0.

Â We can write one half for the probability that M equals ten.

Â It's not going to matter in the end anyway because it's going to go to zero,

Â but there you have it.

Â And so by summing these probabilities we get that the probability that C,

Â the ciphertext is equal to the string rqh, is exactly 1 over 52.

Â Now, recall the definition of perfect secrecy, from the earlier in the lecture.

Â All right, we said that regardless of any prior information the attacker has

Â about the plaintext, the ciphertext that the attacker observes should leak

Â no additional information about the plaintext.

Â What we're going to do now is equate the attacker's information about

Â the plaintext with the attacker known distribution over the plaintext.

Â So, what this means is that perfect secrecy will require that observing

Â the ciphertext should not change the attacker's knowledge about

Â the distribution of the plaintext at all.

Â Right, so the attacker has some knowledge about the distribution of the plaintext

Â before observing the ciphertext.

Â But that's just given by the distribution capital M,

Â the distribution over the possible messages that might be sent.

Â After observing the ciphertext the attacker can update its knowledge about

Â the distribution, and what we require is that a scheme is, is defined as,

Â to be perfectly secret, if, and only if those two distributions, right,

Â the a priori distribution before observing a ciphertext, and the a posteriori

Â distribution, after observing a ciphertext, should be exactly equal.

Â So more formally, what this means, is that an encryption scheme, defined by

Â the algorithms Gen, Enc, and Dec, and the message space bold face M is perfectly

Â secret, if for every possible distribution over the message, over the message space,

Â right, any possible distribution over the possible messages that might be sent.

Â Every message m and every ciphertext c that can occur with non zero probability,

Â it holds that the probability that the message was equal to m

Â conditioned on observing a ciphertext equal to lowercase c is exactly

Â equal to the a priori probability that the message was equal to m in the first place.

Â So we have here an expression, on the right hand side we have the a priori

Â probability with which the message takes on some value lowercase m.

Â Right, this is the attacker's knowledge about the distribution about the plaintext

Â before observing any ciphertext.

Â And we're requiring that to be equal to the left hand side,

Â which is the probability that the message was equal to some value M, conditioned on

Â observing that the ciphertext took on some particular value lowercase c.

Â Okay, so again this is our definition of perfect secrecy.

Â This is just a formalization, a mathematical description of our informal,

Â intuitive notion of security that we had on the previous slide.

Â Now I know the definition is a little bit difficult to get used to, and

Â so what I wanted to do was walk through just two examples of

Â calculations that pertain to that definition.

Â Let's go back to an example we had before, where we had the shift cipher.

Â And again,

Â the distribution where the message is equal to one with probability one half.

Â And the message is equal to ten with the probability one half as well.

Â And let's take as one particular message the string ten and

Â as one particular ciphertext the string rqh.

Â Well, we can then ask, what's the probability that the message was equal

Â to ten conditioned on the fact that we observed a ciphertext equal to rqh?

Â You might already be able to answer this question just based on intuition, but

Â I want to go through the explicit calculation.

Â Well, the reason, we, we can actually say quickly that this is exactly equal to 0.

Â Sorry, I didn't go through the calculation.

Â I'll do that in the next example.

Â Why is that?

Â Okay, well remember what we said before is that the condition on

Â the message being equal to ten.

Â It's simply not possible for the ciphertext to be equal to rqh.

Â There's no key that will map the message M onto the cipher text rqh.

Â What that means is that if we've observed the ciphertext rqh,

Â then it cannot possibly the case, be the case that the message was ten, right?

Â Because again, there's no possible way for

Â the message to be equal to ten and the ciphertext to be equal to rqh.

Â So therefore, the probability that the message is equal to ten,

Â conditioned on the ciphertext being equal to rqh is precisely 0.

Â It's simply not possible that the message was ten given that

Â we've observed the ciphertext rqh going across the channel.

Â The thing to note here is that this is not equal to the a priori probability that

Â the message is equal to ten right?

Â The a priori probability that the message was equal to ten is one half which is

Â not equal to 0.

Â And this shows actually that the shift cipher does not meet the definition of

Â perfect secrecy.

Â I'm going to turn next to a more complicated example, and

Â in analyzing that we're going to use Bayes's theorem.

Â This is something else that I'm assuming that you've seen before but

Â I just wanted to review it very quickly.

Â So Bayes' theorem is just a way of switching the order of two events in

Â a conditional probability statement.

Â And it simply says that the probability of A conditioned on B

Â is equal to the probability of B conditioned on A times the probability of

Â A divided by the probability of B.

Â It's quite easy to derive this on your own from what we had on the previous slides,

Â but in any case, this is the statement that we're going to be using.

Â So, for the next example, we'll make it a little more complicated yet,

Â we'll take again the shift cipher as our example, but

Â now we'll consider a distribution over three possible messages.

Â Right, so there are three different messages that can potentially be sent.

Â We'll have that the message is equal to hi with probability 0.3,

Â the message is equal to no with probability 0.2,

Â and the message is equal to in with probability 0.5.

Â I just made these numbers up.

Â What's now the probability that the message is equal to hi,

Â conditioned on observing the ciphertext being equal to xy?

Â Well, we could rewrite this using Bayes' theorem in the following way.

Â It's just a probability that the ciphertext is equal to xy,

Â conditioned on the message being equal to hi, times the probability that the message

Â is equal to hi, divided by the probability that the ciphertext is equal to xy.

Â And now we just need to calculate each of those probabilities individually.

Â Well, the probability that the ciphertext is equal to xy

Â conditioned on the message being equal to hi is easy to calculate.

Â The prod, get, conditioned on the message being equal to hi,

Â there's exactly a single key that will result in a ciphertext xy.

Â I forget exactly what the shift is but

Â you can see just by exhausting over all 26 possibilities that there's

Â exactly one value of the key that will map the message M onto the ciphertext.

Â Sorry, that will map the message hi onto the ciphertext xy.

Â So therefore the probability that that key is the one that's chosen by

Â the key generation algorithm is exactly 1 over 26.

Â Because again the shift cipher chooses keys uniformly from the space of 26

Â possible keys.

Â More interesting or more complicated,

Â is the computation of the probability that the ciphertext is equal to XY.

Â Here, we'll just go back to the law of total probability that we used before.

Â So the probability that the ciphertext is equal to xy,

Â we can break that up as the sum of three different terms.

Â The first term is the probability that C equals xy conditioned on the message being

Â equal to hi times the probability of hi,

Â which is 0.3, plus the probability that c equals xy conditioned on M equals no,

Â times the probability that M equals no, which was 0.2.

Â Plus the probability that C equals xy conditioned on the event that

Â the message was equal to in times the probability of in which was 0.5.

Â Now the probability that the cipher text is equal to xy,

Â conditioned on the message being equal to hi is 1 over 26 as we said earlier.

Â The probability that the ciphertext is xy conditioned on

Â the message being equal to no is also 1 over 26.

Â There's again exactly one key that will map the message M onto

Â the ciphertext xy and the probability that that key is chosen is exactly 1 over 26.

Â On the other hand the probability that the ciphertext is equal to

Â xy conditioned on the message being equal to in is 0.

Â You can again check that there's no possible key that will

Â map the message in onto the ciphertext xy.

Â And so when we add these up we get a total probability of 1 over 52.

Â Finally, the probability that the message is equal to hi conditioned on C equals xy.

Â We can go back to our previous expression in terms of Bayes' Law,

Â plug in the values that we computed, and compute the value of 0.6.

Â So the probability that the message was equal to hi,

Â conditioned on the ciphertext being equal to xy, is exactly 0.6.

Â And the thing to note again, is that this is not equal to the a priori probability,

Â with which the message was equal to hi, which was 0.3.

Â So this demonstrates again that the shift cipher is not perfectly secret because we

Â found a particular distribution over the message space for

Â which the a priori probability that the message took on some

Â particular value given that the observed ciphertext took on some other value,

Â was not equal to the a priori probability with which the message took on that value.

Â So just to summarize, we see here two examples demonstrating that

Â the shift cipher is not perfectly secret, and the question that

Â remains is how can we construct a perfectly secret scheme, right?

Â We have this nice definition of what perfect secrecy means,

Â this nice definition that encapsulates our intuitive understanding or

Â our intuitive desire for what we want to achieve by an encryption scheme.

Â How can we build an encryption scheme and prove that it satisfies that definition?

Â And this is the problem we'll turn to in the next lecture.

Â Coursera provides universal access to the worldâ€™s best education, partnering with top universities and organizations to offer courses online.