Back to Freecodecamp

Step 66

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

latest1.1 KB
Original Source

--description--

Above the offset variable, create another comment saying Define the offset and the encrypted letter.

--hints--

You should create a comment saying Define the offset and the encrypted letter. Don't forget the # at the beginning.

js
({ test: () => assert.match(code, /#\s*Define\sthe\soffset\sand\sthe\sencrypted\sletter/) })

--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():
    
        # 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
--fcc-editable-region--
            
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)
--fcc-editable-region--