So far, we've been talking pretty generally about

cryptographic systems and focusing primarily on encryption concepts but not decryption.

It makes sense that if you're sending a protected message to someone,

you'd want your recipient to be able to decode the message and read it,

and maybe even reply with a coded message of their own.

So let's check out the first broad category of encryption algorithms and

dive into more details about how it works along with some pros and cons.

When we covered Kerchhoff's principle earlier,

do you remember which component of the cipher is crucial to keep secret? That's right.

The key must be kept private to ensure that

an eavesdropper wouldn't be able to decode encrypted messages.

In this scenario, we're making the assumption that the algorithm in

use is what's referred to as symmetric-key algorithm.

These types of encryption algorithms are called symmetric because

they use the same key to encrypt and decrypt messages.

Let's take a simple example of a symmetric key encryption algorithm

to walk through the overall process of encrypting and decrypting a message.

A substitution cipher is an encryption mechanism

that replaces parts of your plaintext with ciphertext.

Remember our hello world example from earlier.

That's an example of substitution cipher

since we're substituting some characters with different ones.

In this case, the key would be the mapping of characters between

plaintext and ciphertext without knowing what letters get replaced with.

You wouldn't be able to easily decode the ciphertext and recover the plaintext.

If you have the key or the substitution table,

then you can easily reverse the process and decrypt

the coded message by just performing the reverse operation.

A well-known example of a substitution cipher is the Caesar cipher,

which is a substitution alphabet.

In this case, you're replacing characters in the alphabet with

others usually by shifting or rotating the alphabet,

a set of numbers or characters.

The number of the offset is the key.

Another popular example of this is referred to as R O T 13 or ROT-13,

where the alphabet is rotated 13 places,

but really ROT-13 is a Caesar cipher that uses a key of 13.

Let's go back to our hello world example and walk

through encoding it using our ROT-13 cipher.

Our ciphertexts winds up being URYYB JBEYQ.

To reverse this process and go back to the plaintext,

we just performed the reverse operation by

looking up the characters in the output side of the mapping table.

You might notice something about the ROT-13 mapping table

or the fact that we're offsetting the alphabet by 13 characters.

Thirteen is exactly half of the alphabet.

This results in the ROT-13 cipher being an inverse of itself.

What this means is that you can recover the plaintext from

ciphertext by performing the ROT-13 operation on the ciphertext.

If we were to choose a different key, let's say eight,

can we do the same thing? Let's check.

Here's the mapping table for an offset of eight,

which gives us the ciphertext of OLSSV DVYSK.

If we run this through the cipher once more,

we get the following output VSZZC KCFZR.

That doesn't work to reverse the encryption process, does it?

There are two more categories that symmetric key ciphers can be placed into.

They're either block ciphers or they're stream ciphers.

This relates to how the ciphers operate on the plaintext to be encrypted.

A stream cipher as the name implies,

takes a stream of input and encrypts the stream one character or one digit at a time,

outputting one encrypted character or digit at a time.

So, there's a one- to-one relationship between data in and encrypted data out.

The other category of symmetric ciphers is block ciphers.

The cipher takes data in,

places that into a bucket or block of data that's a fixed size,

then encodes that entire block as one unit.

If the data to be encrypted isn't big enough to fill the block,

the extra space will be padded to ensure the plaintext fits into the blocks evenly.

Now generally speaking, stream ciphers are faster and less complex to implement,

but they can be less secure than block ciphers.

If the key generation and handling isn't done properly,

if the same key is used to encrypt data two or more times,

it's possible to break the cipher and to recover the plaintext.

To avoid key reuse,

initialization vector or IV is used.

That's a bit of random data that's integrated into

the encryption key and the resulting combined key is then used to encrypt the data.

The idea behind this is if you have one shared master key,

then generate a one-time encryption key.

That encryption key is used only once by generating

a new key using the master one and the IV.

In order for the encrypted message to be decoded,

the IV must be sent in plaintext along with the encrypted message.

A good example of this can be seen when inspecting the

802.11 frame of a WEP encrypted wireless packet.

The IV is included in plaintext right before the encrypted data payload.

In the next video, we'll explore symmetric encryption in more detail,

illustrating some of the more popular algorithms

and dive into the pros and cons of using symmetric encryption.