Back to Freecodecamp

Step 63

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

latest1.3 KB
Original Source

--description--

You will need to increase the key_index count for the next iteration. To do this, after the line you just added and in the same code block, use the addition assignment operator to increment key_index by one.

--hints--

You should use the += operator to add 1 to key_index inside the else clause body.

js
const commentless_code = __helpers.python.removeComments(code);
const {block_body} = __helpers.python.getBlock(commentless_code, "else");
assert(block_body.match(/key_char\s*=\s*key\s*\[\s*key_index\s*%\s*len\s*\(\s*key\s*\)\s*\]\s*key_index\s*\+=\s*1/));

Your code contains invalid syntax and/or invalid indentation.

js
({test: () => assert(true) })

--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)]
--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)