# Learn String Manipulation by Building a Cipher - Step 69

**URL:** <https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [March 27, 2024, 4:09pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467 "2024-03-27T16:09:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Respect05](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/respect05/32/358120_2.png) [@Respect05](https://forum.freecodecamp.org/u/Respect05)\
**Post date:** [March 27, 2024, 4:09pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/1 "2024-03-27T16:09:45Z")

</div>

### Tell us what’s happening:

I’ve been trying to fix the code, I can’t seems to get through, I need help on how to solve this code.

### Your code so far

```py

# User Editable Region

text = 'Hello Zaira'
custom_key = 'python'

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
        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) % len(alphabet)
            encrypted_text += alphabet[new_index]
    
    return encrypted_text
    
#encryption = vigenere(text,custom_key,direction)
#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/122.0.0.0 Safari/537.36`

### Challenge Information:

Learn String Manipulation by Building a Cipher - Step 69

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-69)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 27, 2024, 4:10pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/2 "2024-03-27T16:10:45Z")

</div>

> Add a third parameter called `direction` to your function definition.

Can you point out what is the function definition in your code?

---

<div class="post-metadata">

**Author:** ![Respect05](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/respect05/32/358120_2.png) [@Respect05](https://forum.freecodecamp.org/u/Respect05)\
**Post date:** [March 27, 2024, 4:17pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/3 "2024-03-27T16:17:32Z")

</div>

def vigenere(message, key):

this is the function definition key

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 27, 2024, 4:18pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/4 "2024-03-27T16:18:01Z")

</div>

have you added a third parameter there?

---

<div class="post-metadata">

**Author:** ![Respect05](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/respect05/32/358120_2.png) [@Respect05](https://forum.freecodecamp.org/u/Respect05)\
**Post date:** [March 27, 2024, 4:19pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/5 "2024-03-27T16:19:56Z")

</div>

Yeah, i just did. Still same

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 27, 2024, 4:39pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/6 "2024-03-27T16:39:28Z")

</div>

show your updated code please

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 26, 2024, 4:40am UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-69/682467/7 "2024-09-26T04:40:17Z")

</div>

Closed on September 26, 2024, 4:40am UTC

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