1 00:00:00,000 --> 00:00:00,510 2 00:00:00,510 --> 00:00:02,280 ZAMYLA CHAN: Now, let's tackle vigenere. 3 00:00:02,280 --> 00:00:05,130 The to-dos are going to be as follows-- 4 00:00:05,130 --> 00:00:07,620 getting the key from the user from the command line, 5 00:00:07,620 --> 00:00:11,650 getting the plaintext prompting for that, encyphering that plaintext, 6 00:00:11,650 --> 00:00:15,810 and then finally printing the ciphertext back to the user. 7 00:00:15,810 --> 00:00:18,240 The key is going to be in the command line argument, 8 00:00:18,240 --> 00:00:20,310 and we can access it as follows-- 9 00:00:20,310 --> 00:00:22,410 using the argv array. 10 00:00:22,410 --> 00:00:25,680 In C, we simply called argv index 1. 11 00:00:25,680 --> 00:00:31,470 And in Python, we'll have to add in a system.argv for that. 12 00:00:31,470 --> 00:00:35,760 Then you'll also want to check to make sure that your key is comprised 13 00:00:35,760 --> 00:00:37,870 of all letters, all alphabetic. 14 00:00:37,870 --> 00:00:41,820 So use that isalpha function here to check for that. 15 00:00:41,820 --> 00:00:46,050 To get the plaintext from the user, prompt them for it using the get_string 16 00:00:46,050 --> 00:00:49,770 function found in the cd50 module. 17 00:00:49,770 --> 00:00:52,260 Now, let's talk about encyphering. 18 00:00:52,260 --> 00:00:56,490 If I wanted to iterate over all of the letters in my name, printing those, 19 00:00:56,490 --> 00:00:59,340 then I could store my name in a variable-- name-- 20 00:00:59,340 --> 00:01:02,550 and then I would execute the for loop as follows-- 21 00:01:02,550 --> 00:01:05,820 for c in name: print(c). 22 00:01:05,820 --> 00:01:09,300 Notice here that the variable c is just a placeholder, the iterator, 23 00:01:09,300 --> 00:01:12,630 for every character in my name. 24 00:01:12,630 --> 00:01:16,470 Now, if I ran this, then the print method 25 00:01:16,470 --> 00:01:19,440 would include a new line after every character. 26 00:01:19,440 --> 00:01:21,570 So make sure to check up on how print works 27 00:01:21,570 --> 00:01:24,930 and how to omit a new line coming automatically 28 00:01:24,930 --> 00:01:27,460 after every call to print. 29 00:01:27,460 --> 00:01:28,260 All right. 30 00:01:28,260 --> 00:01:30,300 So now, that we know at the most basic level 31 00:01:30,300 --> 00:01:35,880 how to iterate over our plaintext, let's look at the formula for vigenere. 32 00:01:35,880 --> 00:01:38,760 Where we have the ith letter of the plaintext shifted 33 00:01:38,760 --> 00:01:43,830 by the jth letter of the key, and all of that is [? moduloed ?] by 26. 34 00:01:43,830 --> 00:01:47,760 And that gives you the ith letter of our cipher text. 35 00:01:47,760 --> 00:01:50,250 So here, you'll notice that, as before, we have 36 00:01:50,250 --> 00:01:52,830 two indices that we're dealing with-- 37 00:01:52,830 --> 00:01:54,570 i and j. 38 00:01:54,570 --> 00:01:57,240 But in the for loop example before, we only 39 00:01:57,240 --> 00:02:01,000 had the capability for one index or one iterator. 40 00:02:01,000 --> 00:02:06,850 So you'll have to find a way to keep track of your second index. 41 00:02:06,850 --> 00:02:10,030 Now, we want to advance that index in the keyword 42 00:02:10,030 --> 00:02:12,460 only if the character in plaintext is a letter, 43 00:02:12,460 --> 00:02:15,280 so go back to the isalpha function. 44 00:02:15,280 --> 00:02:19,240 And as before, with our ciphers, we'll want to preserve the case. 45 00:02:19,240 --> 00:02:24,000 So you might want to use the isupper and islower functions. 46 00:02:24,000 --> 00:02:27,430 Finally, you'll want to implement alphabetical wraparound. 47 00:02:27,430 --> 00:02:30,100 I'll give you a hint to check out these two functions. 48 00:02:30,100 --> 00:02:32,830 And in combination with the formula from before, 49 00:02:32,830 --> 00:02:35,650 figure out how to go back and forth between ASCII 50 00:02:35,650 --> 00:02:38,890 values and alphabetical indices to make sure that you 51 00:02:38,890 --> 00:02:41,560 wraparound the alphabet correctly. 52 00:02:41,560 --> 00:02:45,100 Print the ciphertext back to the user, and you've finished the problem. 53 00:02:45,100 --> 00:02:49,410 My name is Zamyla, and this was vigenere. 54 00:02:49,410 --> 00:02:52,128