Build a Caesar Cipher - Step 25

Tell us what’s happening:

hey so i am almost done with this challenge i think im doing something the code wont pass if someone can point out what i am doing wrong and how to fix it would help alot

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.', 13)
decrypted_text = decrypt(encrypted_text, 3)
print(encrypted_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/143.0.0.0 Safari/537.36

Challenge Information:

Build a Caesar Cipher - Step 25

encrypted_text = encrypt('Pbhentr vf sbhaq va hayvxryl cynprf.', 13)

The instructions say to replace the value assigned to encrypted_text with the string given. What have you done?

I suggest you reset the step if necessary and try again.

Hi, I tried to maintain the second argument to 3 in the encrypt function and only changed the string of the first argument. I figured out, ‘cause I made a mistake when trying to troubleshoot my own code, that to switch the second argument for the encrypt function to 13. However, I already replaced the print function to decrypt and/or made two print function respectively, but it keeps saying to print decrypt. I don’t understand the logic where if I print decrypt the message is gibberish and when both second arguments to print encrypt are the same it gives the readable message. Also, 115 passes the second if condition return call, it was a mistake when I found that out.

I am lost, I am somehow smiling but feeling frustrated.

that’s not what you are asked to do

Replace the value assigned to encrypted_text with the following string, which represents a message to decrypt:

it does not say that the value to encrypted_text should be a function call anymore, it says to replace what’s assigned now with a string, so remove the function call

1 Like