Back to Freecodecamp

Step 3

curriculum/challenges/english/blocks/workshop-caesar-cipher/680a431692a5f863f726c438.md

latest1.6 KB
Original Source

--description--

In this workshop, you are going to build a Caesar cipher. This is one of the simplest techniques to encrypt text, which consists of substituting each letter of the plain text with the letter found at a fixed number of positions down the alphabet. For example, with a shift of 5, a would be replaced by f, b by g and so on.

To implement this cipher, you'll need to create a new version of your alphabet that starts at the position indicated by the shift. As you learned in a previous lesson, you can extract part of a string using string slicing:

py
fcc = 'freeCodeCamp'
print(fcc[8:]) # Camp

Create a variable named shifted_alphabet and use the slicing syntax to assign it the portion of alphabet that starts at the index of shift. Then, call the built-in print() function to print shifted_alphabet on the terminal and look at the result.

--hints--

You should declare a new variable named shifted_alphabet.

js
({ test: () => assert(runPython(`_Node(_code).has_variable("shifted_alphabet")`)) })

You should assign alphabet[shift:] to shifted_alphabet.

js
({ test: () => assert(runPython(`_Node(_code).find_variable("shifted_alphabet").is_equivalent("shifted_alphabet = alphabet[shift:]")`)) })

You should call the print() function passing in shifted_alphabet as an argument.

js
({ test: () => assert(runPython(`_Node(_code).has_call("print(shifted_alphabet)")`)) })

--seed--

--seed-contents--

py
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shift = 5
--fcc-editable-region--

--fcc-editable-region--