Learn String Manipulation by Building a Cipher - Step 63

Tell us what’s happening:

Hi, I have tried looking up previous hints to this question and still not able to get it. This is my code so far and I still get the same answer.
“You should call vigenere passing text and custom_key as the arguments.”
Need help please.

Your code so far

text = 'Hello Zaira'
custom_key = 'python'
encryption = vigenere(text, custom_key)

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

    for char in message.lower():
        # Append space to the message
        if char == ' ':
            encrypted_text += char
            # 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)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]

    return encrypted_text

/* User Editable Region */

vigenere(text, custom_key)

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 63

Please, do not modify the code outside the editable region. You have an error in your code because you are trying to call a function before its declaration. Reset the code and try again. You should get a more useful hint then.

Welcome to the forum

You have the correct code (line 3), however it is in the wrong place.

At the moment, the variable is calling a function which doesn’t exist above the line three.

Happy coding

1 Like

Alternatively, remove this line.

1 Like

Thank you so much, for the help. Have moved code from line 3 to 27 and all good now, code passed…

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.