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

Loading...

來自 University of Maryland, College Park 的課程

Cryptography

436 個評分

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

從本節課中

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.