# Learn String Manipulation by Building a Cipher - Step 63

**URL:** <https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [December 22, 2023, 3:15pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406 "2023-12-22T15:15:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepthevet](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pepthevet/32/322784_2.png) [@pepthevet](https://forum.freecodecamp.org/u/pepthevet)\
**Post date:** [December 22, 2023, 3:15pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/1 "2023-12-22T15:15:05Z")

</div>

### Tell us what’s happening:

Describe your issue in detail here.

### Your code so far

```py
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

/* User Editable Region */

vigenere(text, custom_key)
encryption = encrypted_text

/* User Editable Region */

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:120.0) Gecko/20100101 Firefox/120.0`

### Challenge Information:

Learn String Manipulation by Building a Cipher - Step 63

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

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [December 22, 2023, 3:57pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/2 "2023-12-22T15:57:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pepthevet](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pepthevet/32/322784_2.png) [@pepthevet](https://forum.freecodecamp.org/u/pepthevet)\
**Post date:** [December 22, 2023, 7:18pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/3 "2023-12-22T19:18:04Z")

</div>

Sorry I didn’t write any description.  
The problema is that I don’t understand how to asign the ‘return’ value of the function to the variable ‘encryption’. Any hints?

---

<div class="post-metadata">

**Author:** ![SzeYeung1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/szeyeung1/32/263882_2.png) [@SzeYeung1](https://forum.freecodecamp.org/u/SzeYeung1)\
**Post date:** [December 22, 2023, 7:43pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/4 "2023-12-22T19:43:57Z")

</div>

Let’s see an example.

```auto
def square(a):
    return a*a

```

This simple function returns the square value of `a`. If we want to show the square number of 3, we can use

```auto
print(square(3))

```

Which will show 9 in the output. If you want to assign the return value of that `square` function to an other variable, let’s say `answer`, we use

```auto
answer=square(3)

```

So you know what to do now?

---

<div class="post-metadata">

**Author:** ![SzeYeung1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/szeyeung1/32/263882_2.png) [@SzeYeung1](https://forum.freecodecamp.org/u/SzeYeung1)\
**Post date:** [December 22, 2023, 7:48pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/5 "2023-12-22T19:48:33Z")

</div>

By the way, this is for course developers: I think for complete newbies, it may be confusing to ask them to assign the return value of a function to a variable without giving examples.

---

<div class="post-metadata">

**Author:** ![pepthevet](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pepthevet/32/322784_2.png) [@pepthevet](https://forum.freecodecamp.org/u/pepthevet)\
**Post date:** [December 22, 2023, 8:37pm UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/6 "2023-12-22T20:37:46Z")

</div>

Thanks, that´s what I thought. I even tried coding:  
‘encryption = vigenere(text, custom\_key)’  
several times before posting here, but there must had been a problem with the page as it didn´t return it as ok.  
It did now. Thanks!!

---

<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:** [June 22, 2024, 8:38am UTC](https://forum.freecodecamp.org/t/learn-string-manipulation-by-building-a-cipher-step-63/657406/7 "2024-06-22T08:38:44Z")

</div>

Closed on June 22, 2024, 8:38am UTC

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