Learn String Manipulation by Building a Cipher - Step 83

Tell us what’s happening:

The question says to concatenate using the ‘+’ operator. Then asks to modify print(encryption) so it returns ‘Encrypted text: mrttaqrhknsw ih puggrur’.
However this is shown as incorrect as the function has already ran therefore returning the encrypted text not the original ‘text’ variable. I have tried many,many ways before posting so i’m wondering if the question has been written incorrectly. thanks

Your code so far

text = 'mrttaqrhknsw ih puggrur'
custom_key = 'python'

def vigenere(message, key, direction=1):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    final_message = ''

    for char in message.lower():

        # Append any non-letter character to the message
        if not char.isalpha():
            final_message += char
        else:        
            # Find the right key character to encode/decode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted/decrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset*direction) % len(alphabet)
            final_message += alphabet[new_index]
    
    return final_message

def encrypt(message, key):
    return vigenere(message, key)
    
def decrypt(message, key):
    return vigenere(message, key, -1)

/* User Editable Region */

encryption = encrypt(text, custom_key)
print('Encrypted text: ' +encryption)
decryption = decrypt(encryption, custom_key)
print(decryption)

/* 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/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 83

does it print in the console what it is asked?

‘mrttaqrhknsw ih puggrur’ is the text that is ran through the function to encrypt it, so the function returns the encrypted text as ‘bpmaodgfdugj xf ibutgsk’.

no it print Encrypted text: bpmaodgfdugj xf ibutgsk. and this is correct because that is the original variable but encrypted

but the instructions require

make all the changes needed to get that

that would mean not running the text through the function at all though. however the text above that line is greyed out meaning you cant change it

you need to change only the print, make all the changes needed inside the print

you have not made any changes from before, you know what variable has that value, put it in there

Please post your actual code instead of a screenshot

the text was originally
encryption = encrypt(text, custom_key)
print(encryption)
decryption = decrypt(encryption, cutom_key)
print(decryption)

so i changed it to

print('Encrypted text: ’ +encryption)

however the question is wrong. it asks to print ‘Encrypted text: mrttaqrhknsw ih puggrur’

‘mrttaqrhknsw ih puggrur’ is not the encrypted text, it is the decrypted text or the original variable that goes through the function.

the question should ask for ‘Encrypted text: bpmaodgfdugj xf ibutgsk’ as ‘bpmaodgfdugj xf ibutgsk’ is the encrypted text that the function returns

the question is asking for the wrong output

1 Like

no, the task is asking for the right thing, it’s that encryption is not what you need there

i will keep trying and reply if neccessary, thankyou

thankyou very much for your help ive fixed it

2 Likes

Hey jokey, good night! lucky you. I don’t get it, i´v wrote:

"encryption = encrypt(text, custom_key)
print("Encrypted text: “+ decrypt(encryption,custom_key))”

And erase the left code, in orde to use only the variable declared at this point “encryption”, the output is correct but … the answer it is not and i don’t know the reason

IM STUCKED

you need to use a variable in the print statement, the one with the value you want to print, not a function call

also, welcome to the forum, please always open a topic for your questions

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 Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

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.

this is the solution => EDIT

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.

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.

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