Build a Caesar Cipher - Step 25

Tell us what’s happening:

im unable to sort out this one been tried many times

Your code so far


# User Editable Region

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())
    return text.translate(translation_table)

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


encrypted_text = 'Pbhentr vf sbhaq va hayvxryl cynprf'
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/143.0.0.0 Safari/537.36

Challenge Information:

Build a Caesar Cipher - Step 25

It seems to me that you modified the original code. Please try resetting the workshop. I strongly not recommend modifying the original code (in grey in the background) and only edit the “User editable region” (in white in the background).

It says " You should assign Pbhentr vf sbhaq va hayvxryl cynprf. to encrypted_text .", right?

double check, you are missing a character at the end of the string, with that change your code passes

you have made some changes in areas that you are not expected to change in this step, for this step it’s not an issue, but in other steps it can cause the tests to not pass so I don’t recommend doing that in general

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.