00:00:00,510 --> 00:00:02,280 ZAMYLA CHAN: Now, let's tackle vigenere. The to-dos are going to be as follows-- getting the key from the user from the command line, getting the plaintext prompting for that, encyphering that plaintext, and then finally printing the ciphertext back to the user. The key is going to be in the command line argument, and we can access it as follows-- using the argv array. In C, we simply called argv index 1. And in Python, we'll have to add in a system.argv for that. Then you'll also want to check to make sure that your key is comprised of all letters, all alphabetic. So use that isalpha function here to check for that. To get the plaintext from the user, prompt them for it using the get_string function found in the cd50 module. Now, let's talk about encyphering. If I wanted to iterate over all of the letters in my name, printing those, then I could store my name in a variable-- name-- and then I would execute the for loop as follows-- for c in name: print(c). Notice here that the variable c is just a placeholder, the iterator, for every character in my name. Now, if I ran this, then the print method would include a new line after every character. So make sure to check up on how print works and how to omit a new line coming automatically after every call to print. All right. So now, that we know at the most basic level how to iterate over our plaintext, let's look at the formula for vigenere. Where we have the ith letter of the plaintext shifted by the jth letter of the key, and all of that is [? moduloed ?] by 26. And that gives you the ith letter of our cipher text. So here, you'll notice that, as before, we have two indices that we're dealing with-- i and j. But in the for loop example before, we only had the capability for one index or one iterator. So you'll have to find a way to keep track of your second index. Now, we want to advance that index in the keyword only if the character in plaintext is a letter, so go back to the isalpha function. And as before, with our ciphers, we'll want to preserve the case. So you might want to use the isupper and islower functions. Finally, you'll want to implement alphabetical wraparound. I'll give you a hint to check out these two functions. And in combination with the formula from before, figure out how to go back and forth between ASCII values and alphabetical indices to make sure that you wraparound the alphabet correctly. Print the ciphertext back to the user, and you've finished the problem. My name is Zamyla, and this was vigenere.