1
00:00:02,170 --> 00:00:06,640
Hey, everyone, and welcome back to this class natural language processing in Python.

2
00:00:11,550 --> 00:00:16,770
In this lecture, we are going to begin looking at the code to demonstrate our cipher decryption algorithm.

3
00:00:17,520 --> 00:00:22,170
This particular lecture will focus on how to create the original substitution cipher.

4
00:00:22,890 --> 00:00:24,990
Remember that this is a simulation.

5
00:00:25,500 --> 00:00:28,890
Normally, we don't know the true answer, but in this case we do.

6
00:00:29,490 --> 00:00:35,730
The purpose is that we can compare our answer to the true answer to assess the efficacy of our algorithm.

7
00:00:36,330 --> 00:00:41,790
So our goal by the end of this code is to see if we get the correct answer and we will know what the

8
00:00:41,790 --> 00:00:44,940
correct answer is because that's what we started with.

9
00:00:46,800 --> 00:00:50,810
First, we're going to do all of our usual imports, Nampai and map plot lib.

10
00:00:51,280 --> 00:00:56,310
We'll also need the string library, which provides us with a convenient way to load all the valid ASCII

11
00:00:56,310 --> 00:00:57,030
characters.

12
00:00:57,600 --> 00:01:02,520
We'll need the random library to shuffle the ASCII characters and create our substitution cipher.

13
00:01:03,180 --> 00:01:08,820
We'll need the regex library to do some string operations later on in the scripts, and we'll also need

14
00:01:08,820 --> 00:01:12,870
the O's and Tex rep libraries to do some miscellaneous tasks later on.

15
00:01:17,770 --> 00:01:24,160
So this lecture will focus on this first block of code where we create the substitution cipher to start,

16
00:01:24,160 --> 00:01:27,280
we'll just create two lists of letters, letters one and letters two.

17
00:01:27,880 --> 00:01:30,190
When you call string that ASCII lowercase.

18
00:01:30,520 --> 00:01:34,690
This returns all 26 letters in lowercase in alphabetical order.

19
00:01:35,200 --> 00:01:38,770
You can print them out yourself in order to confirm what I've said is correct.

20
00:01:39,370 --> 00:01:41,500
We also cast the Strings two lists.

21
00:01:41,950 --> 00:01:46,990
This is helpful so we can have one element of each list represent a single character at a time.

22
00:01:48,130 --> 00:01:51,460
Next, we initialize an empty dictionary called True Mapping.

23
00:01:52,150 --> 00:01:57,790
The rest of this code will populate this dictionary, so the next step is to randomize the second list

24
00:01:57,790 --> 00:01:59,500
of letters letters to.

25
00:02:00,130 --> 00:02:04,990
There's no need to randomize the first list since those will just be the keys of the dictionary, and

26
00:02:04,990 --> 00:02:06,940
they'll map to the letters of the second list.

27
00:02:07,780 --> 00:02:10,660
Next, we loop through both lists in corresponding order.

28
00:02:11,230 --> 00:02:13,690
We can accomplish that by using the zip function.

29
00:02:14,320 --> 00:02:19,870
So in the first iteration of this loop, K will be the first element of letters one, and we will be

30
00:02:19,870 --> 00:02:21,430
the first element of letters to.

31
00:02:22,400 --> 00:02:27,290
On the second iteration, Kay will be the second element of letters one, and we will be the second

32
00:02:27,290 --> 00:02:30,260
element of letters to inside the loop.

33
00:02:30,270 --> 00:02:34,790
We assign Kay to be the key of the true mapping and a V to be the value.

34
00:02:35,660 --> 00:02:40,860
Once we complete this loop, the true mapping dictionary will represent our substitution cipher.

35
00:02:41,660 --> 00:02:47,360
Conceptually, only the sender and receiver know what the true mapping is and the intruder does not.

36
00:02:48,050 --> 00:02:51,230
The intruder will use the genetic algorithm we described previously.

37
00:02:53,110 --> 00:02:58,270
So the rest of his lectures are under the assumption that you are the intruder and you're trying to

38
00:02:58,270 --> 00:03:01,840
decrypt the message without knowing what this true mapping is.

