Back to Freecodecamp

Step 64

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6554a57ec0a2c52106e7ee50.md

latest1.0 KB
Original Source

--description--

Inside the else clause, write a comment saying Find the right key character to encode.

--hints--

You should create a comment saying Find the right key character to encode. Don't forget the # at the beginning.

js
({ test: () => assert.match(code, /#\s*Find\sthe\sright\skey\scharacter\sto\sencode/) })

--seed--

--seed-contents--

py

text = 'Hello Zaira'
custom_key = 'python'

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

    for char in message.lower():
--fcc-editable-region--
        # Append space to the message
        if char == ' ':
            encrypted_text += char
        else:
            
            key_char = key[key_index % len(key)]
            key_index += 1
--fcc-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)