Learn String Manipulation by Building a Cipher - Step 66

###I am following the instruction given as I already know and double checked it many times.But it still displays an error saying: You should multiply offset by direction in the new_index assignment. My code so far shows that I«'m already doing it. What am I missing here?

Your code so far

text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key, direction):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in message.lower():
    
        # Append space to the message
        if char == ' ':
            encrypted_text += char
        else:        
            # Find the right key character to encode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)

/* User Editable Region */

            new_index = offset * direction

/* User Editable Region */

            encrypted_text += alphabet[new_index]
    
    return encrypted_text
    
#encryption = vigenere(text, custom_key)
#print(encryption

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 66

Notice the original line is:

new_index = (index + offset) % len(alphabet)

If you want to reverse the encryption operation, should you just modify the value of offset from addition to subtraction, or rewrite the whole line like you did?

1 Like

The step instructs me only to multiply the two variables, which means I have to rewrite the whole line.

Think about what the line will do in either cases, then you may know what the instruction really means to do. Does it really mean to “just assign new_index to the multiplication of the two valuables”, or “just multiply offset by direction in the assignment line of new_index”?

1 Like

Yes, it is something to think about. But the instruction says: “All you have to do is multiply the offset by the direction variable using the * operator in Python.” That kind of restrain my options.

I’m in the same situation

Hey @gerardo.zenga

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

do not delete the whole line, nowhere it says to delete the whole line, add the multiplication inside what’s already written

2 Likes

I’ve solved the issue. Thanks for the help!

1 Like

I solved the issue. Thanks for the help!

1 Like

hi @brunoahlc i’ve tried to add the multiplication of offset by direction to the existing line but still don’t pass.
new_index = (index + offset) % len(alphabet) + offset * direction
Please can you be more detailed on how you went about it? Or additional hints? Thanks.

hi @TAMEU86

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.