Everyone and welcome back to this class natural language processing in Python.
In this lecture, we're going to talk about ciphers specifically, we're interested in one of the simplest
ciphers, the substitution cipher.
Basically, this should be exactly what you think it is.
We create our encoded message by substituting each letter with a different letter.
Let's start with some terminology and a high level picture.
First, we're going to assume that there is some senator and some receiver, and the sender is sending
a message to the receiver.
You are a spy who has intercepted this message.
But of course, it's encrypted, so you can't just read it plainly.
The message was encrypted by the sender before sending the message, and the receiver will decrypt the
message upon receiving it.
Both the sender and the receiver have a dictionary or a mapping such that they can look up at which
letters in the unencrypted message get mapped to which letters in the encrypted message.
This is a one to one mapping, so in order to decrypt the message, we just have to reverse the mapping.
Of course, you as the spy don't have this mapping, so therefore you can't read the message without
having to do some extra work, which is what this section is all about.
Let's do a very simple example.
So you get the basic idea.
Suppose the message we want to send is I like cats.
Now we need to encrypt this message.
We're given this mapping, which tells us how to translate each of the letters here into its encrypted
form.
Since there are 26 letters in the alphabet, let's just focus on the letters we need.
Specifically, I should be replaced with why L should be replaced with W AI again.
It should be replaced with why K should be replaced with R e should be replaced with n c should be replaced
with J.
A should be replaced with l t should be replaced with O and s should be replaced with B.
So our encrypted message becomes y w y are n jello B. Therefore, our sender will send the message y
y are in jail, though b across the internet without transmitting the key, it's assumed that both the
sender and receiver already know how to decrypt the message.
Next, let's pretend that we have a receiver and we just receive this encrypted message.
Our job is now to decrypt this message.
In order to do this, we must apply the same mapping as before, but in reverse order specifically,
why should be replaced with I w should be replaced with L y again.
It should be replaced with AI.
Ah, should be replaced with K and should be replaced with E j should be replaced with C l should be
replaced with a o should be replaced with T and B should be replaced with s.
Therefore YWCA in a jail or B becomes I like cats.
So hopefully, this lecture helps you to understand the basic mechanism behind the substitution cipher
and to understand the basic terminology, you know how to encrypt and decrypt a message and why we want
to solve this problem in the first place.
You now understand your role in the process, which is to crack the code and decrypt the messages without
being given the key.
In the next few lectures, we'll talk about how our understanding of probability will help us in that
pursuit.