Learn String Manipulation by Building a Cipher - Step 72

Tell us what’s happening:

i dont understand call passing 1 as the thirg argument can someone explain pls

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)
            new_index = (index + offset*direction) % len(alphabet)
            encrypted_text += alphabet[new_index]
    
    return encrypted_text
    

# User Editable Region

        encryption = vigenere(text, custom_key)
        print(encryption)

# 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/127.0.0.0 Safari/537.36 OPR/113.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 72

The third parameter is direction. When you call the encryption function with 1 as your direction value, the offset will be a positive value as you are multiplying it by 1. However, if you were to change the value of direction to -1, offset will be negative, so will work in reverse. This is how the function can both encrypt and decrypt. I think this will be illustrated in the steps which follow.

i still dont understands what should i do iam sorry

you need to uncomment the two lines without indenting, and add 1 as third argument for vigenere

1 Like

Sorry, I misunderstood your question. I thought you were asking why direction has a value of 1.

solution code removed

solution code removed

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.