Learn String Manipulation by Building a Cipher - Step 83

Tell us what’s happening:

Step 83
Delete the pass keyword, and return vigenere(message, key) from your new function.

def encrypt(message, key):
encryption = vigenere(message, key)
print(encryption)
decryption = vigenere(message, key, -1)
print(decryption)

I simply dont know how do I have to modify my code for it to work properly.

Your code so far

text = 'Hello Zaira!'
custom_key = 'python'

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

    for char in message.lower():

        # Append any non-letter character to the message
        if not char.isalpha():
            final_message += char
        else:        
            # Find the right key character to encode/decode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted/decrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset*direction) % len(alphabet)
            final_message += alphabet[new_index]
    
    return final_message

# User Editable Region

def encrypt(message, key):
encryption = vigenere(message, key)
print(encryption)
decryption = vigenere(message, key, -1)
print(decryption)


# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 83

Delete the pass keyword, and return vigenere(message, key) from your new function.

You did half of the job.

dude I know that, help me with the other half common

Do you know how to return something? You already did it here:

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

    for char in message.lower():

        # Append any non-letter character to the message
        if not char.isalpha():
            final_message += char
        else:        
            # Find the right key character to encode/decode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted/decrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset*direction) % len(alphabet)
            final_message += alphabet[new_index]
    
    return final_message

# User Editable Region

def encrypt(message, key):
  encryption = vigenere(message, key)
  print(encryption)

def decrypt(message, key):
  decryption = vigenere(message, key, 1)
  print(decryption)

text = 'Hello Zaira!'
custom_key = 'python'

encrypt(text, custom_key)
decrypt(text, custom_key)

Solution: add indentation to the encrypt function and call the encrypt function

I am stupid, already indented and called it and nothing happened.

Please, share your updated code.

def vigenere(message, key, direction=1):
key_index = 0
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
final_message = ‘’

for char in message.lower():

    # Append any non-letter character to the message
    if not char.isalpha():
        final_message += char
    else:        
        # Find the right key character to encode/decode
        key_char = key[key_index % len(key)]
        key_index += 1

        # Define the offset and the encrypted/decrypted letter
        offset = alphabet.index(key_char)
        index = alphabet.find(char)
        new_index = (index + offset*direction) % len(alphabet)
        final_message += alphabet[new_index]

return final_message

User Editable Region

    def encrypt(message, key):
    encryption = vigenere(message, key)
    print(encryption)
    decryption = vigenere(message, key, -1)
    print(decryption)
return encrypt

I’m not sure if the indentation is messed up. I suggest you to reset the code for this step. Then, after you delete pass, you need to write a single line of code, with the same indentation of pass.

To return something you have to write return followed by what you want to return. And you want to return vigenere(message, key).

If this does not help you I don’t have other words to say it.

Hi @romo.emi19

Here is a comparison of your code and the original code.
image

The original code is in blue, your code in in red.
The overlap is in magenta.

As @Dario_DC suggested, the indentation of four lines of code appear to have changed, shown on the top half of the image.

The second half shows your code with the correct indentation.
You appear to have changed some of the code, which the instructions did not ask you to do.

Happy coding