Build a Caesar Cipher - Step 23

Tell us what’s happening:

Step 23 of Caesar Cipher

def encrypt(text, shift):
return ‘caesar(text, shift)’
def decrypt(text, shift):
return ‘caesar(text, shift)’

I created the encrypt and decrypt functions just like how I created the caesar function. But it keeps saying that the encrypt function must return the caesar function? Am I reading this correctly? I also did a number of modifications and the one above is my latest attempt.

Your code so far

def caesar(text, shift, encrypt=True):

    if not isinstance(shift, int):
        return 'Shift must be an integer value.'

    if shift < 1 or shift > 25:
        return 'Shift must be an integer between 1 and 25.'

    alphabet = 'abcdefghijklmnopqrstuvwxyz'

    if not encrypt:
        shift = - shift
    
    shifted_alphabet = alphabet[shift:] + alphabet[:shift]
    translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
    encrypted_text = text.translate(translation_table)
    return encrypted_text


# User Editable Region

def encrypt(text, shift):
    return caesar(text, shift)
def decrypt(text, shift):
    return caesar(text, shift)

# User Editable Region


encrypted_text = caesar('freeCodeCamp', 3)
print(encrypted_text)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build a Caesar Cipher - Step 23

Done! Sorry for the trouble. In one of my coding, I put encrypt=False in the decrypt function as an argument, it turns out it was not quite there. I tried so many mixes that everything got jumbled in my head.

Man, how do you solve it? I’m trying for hours.

def encrypt(text, shift):
    return caesar(text, shift)

def decrypt(text, shift):
    return caesar(text, shift, False)

Is that correct?

try this

code removed by moderator

hi @raghavakurapati007

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

hi @yan.dooom please create your own topic

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.