Learn String Manipulation by Building a Cipher - Step 57

Tell us what’s happening:

Describe your issue in detail here.

Your code so far


text = 'Hello Zaira'
custom_key = 'python'

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

    for char in message.lower():

/* User Editable Region */

        # Append space to the message
        if char == ' ':
            encrypted_text += char
        else:
          key_char = key[key_index % len(key)]

/* User Editable Region */

            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)

Your browser information:

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 57

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

I got stuck at the same step, chat GPT provided the below answer:

Mod Edit SOLUTION REMOVED

personally cannot understand what key and key_index represants.
From the above answer i see that the code entirely takem from the order of condition

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.

You could try asking chatgpt ? It should be able to explain it. More important than passing the test here is to learn and understand the code.

Check all of your indentation. Indentation is syntax in Python and defines the structure of the if/else, so it must be perfect and consistent.

As recommended i will encourage you to do more research on it, to make it easier for you, let me give you some hints.

  1. See the key as a word or phrase that determines the shift applied to each letter in the message.
  2. Then see the key_index as a variable used in keeping track of the current position in the key string. For better understanding please use chatGPT to look for demonstration, illustration or usage of those two in a more simpler code as that will aid your understanding.

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