Back to Freecodecamp

Step 57

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6553f8c570f9982e013a8886.md

latest1.4 KB
Original Source

--description--

Currently, every single letter is always encrypted with the same letter, depending on the specified offset. What if the offset were different for each letter? That would be much more difficult to decrypt. This algorithm is referred to as the Vigenère cipher, where the offset for each letter is determined by another text, called the key.

Start transforming your Caesar cipher into a Vigenère cipher by removing the two function calls.

--hints--

You should remove your two caesar() function calls.

js
({ test: () => {
    const commentless_code = __helpers.python.removeComments(code);
    assert.isFalse(/^caesar\s*\(\s*text\s*,\s*shift\s*\)/m.test(commentless_code))
    assert.isFalse(/^caesar\s*\(\s*text\s*,\s*13\s*\)/m.test(commentless_code))
  }
})

--seed--

--seed-contents--

py
--fcc-editable-region--
text = 'Hello Zaira'
shift = 3

def caesar(message, offset):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in message.lower():
        if char == ' ':
            encrypted_text += char
        else:
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)

caesar(text, shift)
caesar(text, 13)
--fcc-editable-region--