Build a Caesar Cipher - Step 25

Tell us what’s happening:

I have tried doing this in a few different ways, but I just can’t seem to get it right. Do I need to get rid of the print(encrypted_text)?

I have copied and pasted the new message multiple times, while also typing it in manually and nothing is seeming to work.

I feel like this one shouldn’t be that hard, I was able to get through the other questions with ease.

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

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

# User Editable Region

encrypted_text = encrypt('Pbhentr vf sbhaq va hayvxryl cynprf.', 3)
print(encrypted_text)
decrypted_text = decrypt(encrypted_text, 13)
print(decrypted_text)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0

Challenge Information:

Build a Caesar Cipher - Step 25

Welcome back to the forum @ethan24579

You should assign Pbhentr vf sbhaq va hayvxryl cynprf. to encrypted_text.

You are not asked to call a function.

For this step you are asked to assign a string to a variable.

Happy coding

I am glad to be back. Thank you for the clarification, it seems that I was just interpreting / reading the task wrong.

Solved!

1 Like