Back to Freecodecamp

Step 78

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6555d8b0b3d20b128bdadd37.md

latest1.2 KB
Original Source

--description--

Now you can remove the third argument from your first function call.

--hints--

You should remove the third argument from vigenere(text, custom_key, 1).

js
({ test: () => assert.match(code, /vigenere\s*\(\s*text\s*,\s*custom_key\s*\)/) })

--seed--

--seed-contents--

py
text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key, direction=1):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    final_message = ''

    for char in message.lower():
    
        # Append space to the message
        if char == ' ':
            final_message += char
        else:        
            # Find the right key character to encode/decode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted/decrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset*direction) % len(alphabet)
            final_message += alphabet[new_index]
    
    return final_message
--fcc-editable-region--    
encryption = vigenere(text, custom_key, 1)
print(encryption)
decryption = vigenere(encryption, custom_key, -1)
print(decryption)
--fcc-editable-region--