Learn String Manipulation by Building a Cipher - Step 85

Next, modify your encryption and decryption variables by calling encrypt and decrypt , respectively, in place of vigenere

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):
    return encrypt(message, key)
    
def decrypt(message, key):
    return decrypt(message, key, -1)
    
encrypt = encrypt(text, custom_key)
print(encryption)
decrypt = decrypt(encryption, custom_key, -1)
print(decrypt)

# 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/121.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 85

Welcome to the forum @Leack

Here are the instructions:

Next, modify your encryption and decryption variables by calling encrypt and decrypt , respectively, in place of vigenere .

You modified the return statements, this was not asked in the instructions.
You also modified one of the values of the variables.
You used the incorrect name for the variables..

Please reset the step to restore the orignal code.
Then only modify the code you are asked to.

The tests make specific tests in the code.
Altering any part of the code you are not asked to will fail the tests.

Happy coding

2 Likes

i also found out i had to remove the -1 too.

thank you so much for your help

4 Likes

Hi Leack!
I was stuck on the same point just a few mins ago :slight_smile: and just figured it out. Once you reset the lesson as Teller said, also check your ‘decryption’ variable and notice how the decrypt() function was defined to take two parameters, but the previous vigenere() called in decryption has 3; once you replace vigenere() with decrypt() remove the -1 at the end and Voila! Here is my end code:

solution removed

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you and noted for the future. This was my first comment ever in the forum, and I wasn’t aware of the spoiler solutions initiative. I got carried away with the excitement of getting passed that point and thought I was helping out a peer.

1 Like

No problem, totally understandable

i already found out about the answer but thank you for the help tho :smiley:

1 Like

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