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

415 ratings

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

In this lecture, I just wanted to cover some basic background,

Â in hexidecimal notation and ASCII representation.

Â This is the kind of material that you've probably seen already,

Â if you're a computer science undergraduate.

Â On the other hand, it's also the sort of material that people sometimes assume that

Â the students know, and so depending on the exact sequence of courses you've taken and

Â the professors with whom you've taken them,

Â you may never have seen this material explicitly presented in any class.

Â I also wanted to cover this material, for those of you who aren't

Â computer science majors, so that you'll be able to follow the following lecture,

Â where we describe an implementation of the onetime pad scheme.

Â So, hexadecimal notation is just a way of describing integers,

Â in a different base other than the usual decimal base that we're familiar with.

Â Hexadecimal notation uses base 16, which mean that as opposed to the standard 10

Â digits that we're used to, we're going to use a system in which there are 16 digits.

Â Those digits are represented by the numbers 0 through 9,

Â along with the six letters A through F.

Â And as indicated in the table here, each of

Â those hexadecimal digits corresponds to a different value in the range of 0 to 15.

Â So the hex digits 0 through 9 correspond, correspond to the values 0 through 9.

Â And then the hex digit A corresponds to 10, the hex digit B corresponds to 11,

Â and so on up through the hex digit F which corresponds to the value 15.

Â Hex digits are also very convenient because,

Â there's a one to one correspondence between each hex digit, and

Â sequences of four bits, which are sometimes also called a nibble.

Â Right, four bits, is exactly half of a byte, which is eight bits.

Â And so a sequence of four bits is sometimes also referred to as a nibble.

Â So as you see here, again, the hex digit 0 corresponds to the nibble 0000, and so on,

Â up through the hex digit F, which corresponds to the nibble 1111.

Â Now, these correspondences aren't arbitrary.

Â What you'll see is that each core,

Â each hex digit corresponding to a particular nibble.

Â Corresponds to the value of that nibble, if you view it as a binary integers.

Â So just as an example, if we look at the hex digit F.

Â Right. That corresponds to the nibble 1111.

Â And in binary notation, the value 1111.

Â Corresponds to the number that we obtain, or the value that we obtain.

Â By adding 1 plus 2 plus 4 plus 8.

Â Right, each successive sequence in

Â a binary number has value twice the preceding one.

Â So, 1 plus 2 plus 4 plus 8 is in fact equal to the value 15 which is

Â the value that corresponds to the hex digit F.

Â We can work through just a simple example to see how hex,

Â the values of hex numbers can be calculated.

Â So a value in hex is very often represented,

Â by prepending the prefix 0x to the value.

Â So if we try to calculate the value, of the hex number 10, well,

Â just as in, the, as the case in decimals, where each position is, has value ten

Â times the previous one, and in binary each position has value twice the previous one,

Â in hexadecimal notation, each position has value 16 times the previous one.

Â So the hex number ten, has value equal to 16 times 1,

Â plus 0 times 1, which in this case just reduces to 0.

Â So, the value of the hex number 10,

Â is equal to 16, represented in standard decimal notation.

Â We can also represent that.

Â In terms of binary representation.

Â And it's very easy to do that exactly because each hex digit

Â corresponds to a nibble.

Â So if we try to write out the binary representation of the hex number ten,

Â well we can just express that as the nibble corresponding to one followed by

Â the nibble corresponding to zero.

Â And that's just 0001 0000.

Â And again that corresponds

Â to the value 16 if we view that 8 bit number as a binary number.

Â Right, here we have only a single 1 in the fifth position.

Â The fifth position in a binary number has value 16.

Â And so the binary integer 0001 0000 is exactly equal to 16,

Â and everything works out nicely.

Â Just as a second example I have the hexidecimal number, AF.

Â AF is equal to.

Â Or has value 16 times the value of A plus the value of

Â F times 1, the value of A is 10 the value of F is 15.

Â So we have 16 times 10 plus 15 times 1 is equal to 175,

Â and so the hex number AF is equal to the decimal number 175.

Â And again if you write that out in binary then the hex number AF is equal to

Â the binary number 1010 1111, and you can check for yourself the view it

Â as number in binary that is indeed equal to the decimal number 175.

Â So nothing very magical or mysterious there.

Â The next thing I wanted to talk about briefly is ASCII representation.

Â Right, ultimately everything in a computer is represented as bits.

Â And ASCII representation is very often used to

Â represent english letters or characters.

Â In ASCII representation each character is represented using 1 byte,

Â or 8 bits, or equivalently, 2 hex digits.

Â Here we have a table indicating the correspondents between characters in

Â the English alphabet along with other characters as well, and

Â their corresponding ASCII equivalent,

Â you can find this table online I just included it here for convenience.

Â You can see that alongside every character the table includes both their

Â ASCII representation written in Hex, as well as in decimal.

Â Again, that's just for convenience, and you can check that all the numbers line up

Â by perform, by performing a calculation just like we did a moment ago.

Â So, just to go walk through an example, if we look at the character 1, right,

Â which is the, the numeral 1, that has value, hex 31 in the ASCII representation.

Â So that means that if you have a file, say, and

Â somewhere in that file you have the character 1, that would actually be

Â recorded in your computer as the hex value 31, or really, what, at the lower level,

Â it would be represented as a sequence of bits, 0011 0001.

Â Right, so the nibble corresponding to 3, and the nibble corresponding to 1.

Â The key thing I'm pointing out here,

Â is that the character 1 is not the same thing as the number 1, right?

Â The character 1 is just a character, and it's arbitrarily been assigned the ASCII

Â value, the ASCII or the value in the ASCII representation, of hex 31.

Â And if you have a character 1 in a file, it's not stored as a single bit 1,

Â it's stored as the byte given by what is displayed here 00110001.

Â And similarly if we are representing the character capital F,

Â will the character F correspond in the ASCII representation to the value hex 46?

Â Which corresponds to the sequence of 8 bits.

Â 0100. 0110. and so the character F in a file would

Â ultimately be represented in your computer as the sequence of 8 bits described here.

Â Now one point I want to make and this a bit of an advance point.

Â And if you don't understand it I wouldn't really worry about it very much.

Â But this is going to come into play when we sale the implementation of

Â the one time pad in the next lecture.

Â The question is how should we store the value hex 1 F for example to a file.

Â And there are two natural ways we can go about doing this.

Â The first possibility is what I'll call native hex.

Â So we'll store the value exactly as a sequence of bits that it represents.

Â So we've seen already that the hex value 1F corresponds to the sequence of

Â eight bits, 0001 1111.

Â So what we could do is just store the value, hex 1F,

Â to a file as a sequence of eight bits 0001 1111.

Â Now that's all well and good, the problem with that is that if we then try to view

Â that file using a standard text editor, we'll get an unprintable character.

Â And if you go back and look at the ASCII table, you'll see that the hex value 1F,

Â corresponds to some unprintable character, not a regular character in the alphabet,

Â or a numeral, or a punctuation, or anything like that.

Â That's okay if all you're doing is reading to that file from a program, but it's

Â inconvenient if we're trying to look at the file or manipulate the file by hand.

Â A second possibility, is to store the hex value 1F.

Â As the ASCII characters 1F.

Â If we do that then recall that every ASCII character, is represented using one bit so

Â what we now have is something stored using two bits rather than one.

Â That is using 16 bits rather than 8.

Â But if we store the ASCII characters 1F to a file,

Â then what we'll actually end up storing in terms of bits is 0011 0001 0100 0110.

Â All right, we'll try to obtain just by looking up

Â the character 1 in the ASCII file, the character F in the ASCII file,

Â and writing out their corresponding representations.

Â Now, if we view this file using a text editor or

Â from the command line, we see what we expect.

Â We see the characters 1F, if we read it from a program,

Â then what the program is going to see is that sequence of 16 bits.

Â And so we just need to be careful to tell the program to

Â convert that sequence of 16 bits into the hex value 1F.

Â For many programs there's a standard way provided to do that

Â it's also not extremely difficult to do that on your own or

Â to build a small macro to do it on your own.

Â You just have to be careful to keep track of how you're representing your

Â hex values in the file.

Â We'll see this come into play in a little bit more detail in the following lecture.

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