1 00:00:00,420 --> 00:00:07,770 Welcome to the last session in our final hacking advanced level class, which is basically about prime 2 00:00:07,770 --> 00:00:08,270 numbers. 3 00:00:08,550 --> 00:00:15,380 And in this session, we are going to learn about how to find out how to create or generate our prime 4 00:00:15,400 --> 00:00:15,860 numbers. 5 00:00:16,110 --> 00:00:21,170 So the first thing we would be doing is in our program that we would be creating. 6 00:00:21,180 --> 00:00:22,620 We define some functions. 7 00:00:22,860 --> 00:00:29,850 One is, is crime trial, the I.V., which uses the trial division algorithm to return to the number 8 00:00:30,180 --> 00:00:30,350 two. 9 00:00:30,360 --> 00:00:32,640 It is a primer fall to the number two. 10 00:00:32,670 --> 00:00:33,640 It does not apply. 11 00:00:34,230 --> 00:00:40,560 The next thing we want this time of function, which uses Sèvres of an algorithm to generate the prime 12 00:00:40,560 --> 00:00:41,060 numbers. 13 00:00:41,430 --> 00:00:47,340 We want the rubbin function, which uses the algorithm to check whether the number of pastorate is applying. 14 00:00:47,670 --> 00:00:53,550 And this algorithm, unlike the trial division algorithm, can work equally or quickly on a very large 15 00:00:53,550 --> 00:00:58,210 number of this function called not directly, but rather than is brain function. 16 00:00:58,560 --> 00:01:04,260 So we have another function that this is is called when the user must determine whether the large integer 17 00:01:04,260 --> 00:01:09,660 is prime or not, and the last one is generated large by Britain's or large prime number. 18 00:01:09,660 --> 00:01:11,490 That is hundreds of digital. 19 00:01:11,970 --> 00:01:16,730 So over here, we will start creating this particular code so quickly. 20 00:01:17,070 --> 00:01:24,750 My first of all, C five, and then we will fight and we would first do here and import of math and 21 00:01:25,500 --> 00:01:26,820 require random. 22 00:01:27,240 --> 00:01:35,850 Then the first thing we will be defining is the is prime trial division, which takes numbers as the 23 00:01:35,850 --> 00:01:41,910 parameters and this returns true if numbers are prime number otherwise fours and uses the trial division 24 00:01:41,910 --> 00:01:44,360 algorithm for testing the primatology. 25 00:01:44,640 --> 00:01:47,440 So all numbers then two are not right. 26 00:01:47,460 --> 00:01:54,720 So if we check over here directly, we open the function here like this and check if the numbers to 27 00:01:54,720 --> 00:02:02,340 it is less, then do we simply return the value false and then see if number is divisible by any other 28 00:02:02,340 --> 00:02:04,230 number up to the square root of NUM. 29 00:02:04,470 --> 00:02:15,540 So for that we are an affordable thing for I in the range of from to fill in and you take the square 30 00:02:15,540 --> 00:02:30,640 root of num plus one and in this for loop which if num modulo I is equal to zero then return false otherwise. 31 00:02:30,720 --> 00:02:33,390 Finally we say return true. 32 00:02:34,470 --> 00:02:41,820 Now after this function we require the next function that this prime sieff, which takes up an amateur 33 00:02:42,630 --> 00:02:43,260 of size. 34 00:02:44,190 --> 00:02:52,280 And inside of this we return the list of prime numbers calculated using this Sèvres of the algorithm. 35 00:02:52,950 --> 00:03:02,270 So over here we see this is equal to say true, multiplied by the Sèvres size. 36 00:03:02,610 --> 00:03:06,900 Then we say, see that the index zero is equal to force. 37 00:03:07,140 --> 00:03:09,930 That zero and one are not prime numbers. 38 00:03:09,930 --> 00:03:16,710 Hence we have done this and the next we take C that the index one is equal to force, then to create 39 00:03:16,710 --> 00:03:28,290 the C, C for I in the range of starting from two again in my thought square root we take your C size 40 00:03:29,190 --> 00:03:38,590 plus one and here we take all variable pointer which is equal to I multiplied by two and save. 41 00:03:38,600 --> 00:03:48,820 While the value of pointer is less than the value of C size, then you say see the index of pointer 42 00:03:49,680 --> 00:03:57,150 is equal to false and C point of plus is equal to the value of right. 43 00:03:57,510 --> 00:04:06,590 After this we compiled a list of prime numbers by saying over here we say primes is equal to open close 44 00:04:06,600 --> 00:04:07,080 bracket. 45 00:04:07,080 --> 00:04:23,100 And for I in the range of C size we say if your C that the index of Pi is equal to true, then we say 46 00:04:23,100 --> 00:04:32,480 primes dot append in that the value of I finally will return the value of primes from this function. 47 00:04:33,180 --> 00:04:41,580 Then next we have a definition for Robin Miller, which is another function, that is Robin Miller, 48 00:04:42,030 --> 00:04:43,990 which takes again another parameter. 49 00:04:44,100 --> 00:04:47,100 And in this it returns true if numbers are prime number. 50 00:04:47,370 --> 00:04:57,530 So over here we check if num modulo two is equal to zero or we use numbers less than two, then we see 51 00:04:57,720 --> 00:04:59,820 the likely return force that is. 52 00:05:00,180 --> 00:05:07,240 Robin Miller doesn't walk on even in details, so next we check if the value of NAM is equal to three, 53 00:05:07,730 --> 00:05:15,080 then we see the value through and said X is equal to, say, minus one. 54 00:05:17,470 --> 00:05:23,500 And this is equal to say zero, then we say while it's modulo two. 55 00:05:25,260 --> 00:05:31,150 Which is equal to zero, then keep having it until it is over. 56 00:05:31,860 --> 00:05:42,090 So we say X is equal to s double slash two and the plus is equal to one, then result, say, four trials 57 00:05:43,320 --> 00:05:45,810 in the range of five. 58 00:05:46,290 --> 00:05:49,830 We tried to force the numbers primally three to five times. 59 00:05:49,830 --> 00:05:53,700 So we say here A is equal to we use random thought. 60 00:05:54,030 --> 00:06:07,040 We use around the range of say to Bill number minus one and we take V is equal to power of eight if 61 00:06:07,230 --> 00:06:07,700 no. 62 00:06:08,910 --> 00:06:14,400 After which we check if V is not equal to one. 63 00:06:14,910 --> 00:06:16,410 This, this does not apply. 64 00:06:16,430 --> 00:06:17,550 V is equal to one. 65 00:06:17,560 --> 00:06:25,440 So we say here is equal to zero and then we say V not equal to number minus one. 66 00:06:26,070 --> 00:06:32,130 We check if I is equal to three minus one we return here. 67 00:06:32,520 --> 00:06:33,360 False. 68 00:06:34,890 --> 00:06:44,010 Then we have the l thought you would be saying I was two plus one, we will stop the double strip to 69 00:06:44,460 --> 00:06:46,780 modulo the value of numbers. 70 00:06:47,220 --> 00:06:50,520 And finally, we use a written statement. 71 00:06:51,510 --> 00:06:58,200 Now, most of the time, we can quickly determine if no is not a crime by dividing the first few dozen 72 00:06:58,200 --> 00:06:58,990 prime numbers. 73 00:06:59,280 --> 00:07:03,400 Now, this is a clear cut and Robin Miller does not detect all compositions. 74 00:07:03,690 --> 00:07:12,660 So over here, we define first Cee Lo on score rhymes, which is a constant and that is equal to we 75 00:07:12,660 --> 00:07:17,770 call here Prime Sèvres and Farse Hundred. 76 00:07:18,450 --> 00:07:21,770 Now this time, C is a function that we have defined here. 77 00:07:22,050 --> 00:07:29,520 So let us take it in the same case that we have defined, not after this particular definition we define 78 00:07:29,520 --> 00:07:34,040 here and is prime matter, which takes no parameters. 79 00:07:34,260 --> 00:07:36,840 And this returns true if no subprime. 80 00:07:36,840 --> 00:07:41,780 No, this function does a quick subprime no check before calling Veerappan. 81 00:07:42,300 --> 00:07:48,410 So here we do if synonomous less than two we say return false. 82 00:07:49,020 --> 00:07:53,550 And after this we say for subprime in your. 83 00:07:54,810 --> 00:08:05,990 Low price, then we check, if no more prime comes to zero, then we see little falls. 84 00:08:06,660 --> 00:08:10,590 If all else fails, then call the Robin Miller to determine if no. 85 00:08:11,250 --> 00:08:12,990 So after this, then we see. 86 00:08:15,060 --> 00:08:24,990 The value of Robin Miller with passing that number and once you have done that, then the last thing 87 00:08:24,990 --> 00:08:30,090 we are supposed to define is see, generate the large. 88 00:08:32,170 --> 00:08:38,140 Prime, what we are giving here, a key size that's equal to seven zero two four. 89 00:08:38,380 --> 00:08:42,640 And in this we are returning our random prime number that is key size. 90 00:08:42,640 --> 00:08:51,650 But in sizes, we are saying here, while true, we define the number is equal to the random dog or 91 00:08:51,700 --> 00:09:02,770 random range, that is two multiplied by the size minus one, and then giving you two multiplied by 92 00:09:02,770 --> 00:09:04,560 the size. 93 00:09:05,170 --> 00:09:13,570 And then we check if his prime force, the number that is, if it is true, then you are returning the 94 00:09:13,570 --> 00:09:14,800 value of numbers. 95 00:09:15,220 --> 00:09:20,020 Now if you want to see the output, you will have to enter something in the interactive shell. 96 00:09:20,030 --> 00:09:28,230 First thing is we will save this and we will see it again in the drive in our advanced level course. 97 00:09:28,510 --> 00:09:34,590 Let's give this prime number and let us save this. 98 00:09:34,930 --> 00:09:37,560 Now, let us go back to the interactive shell here. 99 00:09:38,170 --> 00:09:43,570 And in this whole thing is we will import the prime number. 100 00:09:44,890 --> 00:09:46,240 Have made a mistake. 101 00:09:46,270 --> 00:09:48,460 Let's go back here now. 102 00:09:48,490 --> 00:09:49,300 What is that? 103 00:09:49,390 --> 00:09:51,310 It is flying. 104 00:09:51,320 --> 00:09:52,610 Steve is not defined. 105 00:09:52,630 --> 00:09:56,500 OK, so we have this defined here flying. 106 00:09:56,500 --> 00:09:59,140 Steve and I be using it. 107 00:10:00,660 --> 00:10:01,680 Let's see below. 108 00:10:02,970 --> 00:10:06,710 Also, it is defined properly, no issues. 109 00:10:08,000 --> 00:10:11,730 Fine, so Sèvres is not defined. 110 00:10:11,750 --> 00:10:12,340 OK. 111 00:10:13,580 --> 00:10:15,830 Made a mistake in defining it. 112 00:10:17,750 --> 00:10:24,910 Let's have a look this month that is over sea size that we are finding in the plains. 113 00:10:25,970 --> 00:10:31,730 So let's just look at the school that we have defined in the metal flying. 114 00:10:31,730 --> 00:10:39,710 SEIFE So here we are defining force to see if that is equal to true, multiplied by the sea size. 115 00:10:41,080 --> 00:10:50,140 And then we are using, you see, the zettl that is equal to force, I'm adding this one is also equal 116 00:10:50,140 --> 00:10:50,790 to force. 117 00:10:50,850 --> 00:10:51,310 OK. 118 00:10:55,920 --> 00:11:03,690 So this is where we have to find this, let's save it and again, try to execute it. 119 00:11:04,470 --> 00:11:10,260 So this is working out and then we say, frim God, now let's call Lemaitre. 120 00:11:10,290 --> 00:11:11,250 That is our. 121 00:11:13,160 --> 00:11:16,010 Generate large size. 122 00:11:17,990 --> 00:11:24,230 So we call this material to generate some large prime number, which is this particular value. 123 00:11:24,260 --> 00:11:33,100 Similarly, if we see prime numbers, DOT, we call is bright and we pass some number to find out if 124 00:11:33,110 --> 00:11:34,410 it is a crime. 125 00:11:34,440 --> 00:11:35,680 But it is a very large number. 126 00:11:35,720 --> 00:11:37,050 It gives us the value falls. 127 00:11:37,430 --> 00:11:42,760 Similarly, we say prime number is prime. 128 00:11:43,070 --> 00:11:45,610 Let's pass the small number to it again. 129 00:11:45,680 --> 00:11:46,710 Value comes first. 130 00:11:47,000 --> 00:11:53,170 So importing this model lets you generate the large numbers using we generate large brain function and 131 00:11:53,170 --> 00:11:58,430 it also ties or lets us pass any number, large or small, to the prime function to determine whether 132 00:11:58,430 --> 00:11:59,480 it is a PIN number. 133 00:11:59,840 --> 00:12:04,580 So finding out a very large number, if it is a prime number or not, is very much easy if we use this 134 00:12:04,580 --> 00:12:07,390 particular code that we have created here. 135 00:12:07,910 --> 00:12:13,880 So with this, we have completed the python having advanced level codes where we have seen a lot of 136 00:12:13,880 --> 00:12:19,700 examples on different types of Hocking's and how the example basically Vogues with many new functions 137 00:12:19,700 --> 00:12:20,650 that we have used. 138 00:12:20,930 --> 00:12:26,870 So you can try out all those functions or all those examples that we have done, and then the next thing 139 00:12:26,870 --> 00:12:29,460 we will move on with some different concepts. 140 00:12:29,690 --> 00:12:35,150 So that's it from this session of generating large prime numbers of Python. 141 00:12:35,630 --> 00:12:36,500 Thank you very much.