Learn String Manipulation by Building a Cipher - Step 83

Tell us what’s happening:

I modified the print(encryption) to print('Encrypted text: ’ + text). It shows that I have accurately printed “Encrypted text: mrttaqrhknsw ih puggrur” , but it’s saying something isn’t right. Any clarity would help!!??

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
            # 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: ' + text)
decryption = decrypt(encryption, custom_key)

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 83

Hello! @mlrtym

The problem is with the spacing… 'Encrypted text: ' is right. One space after the :


"Enter a num: " than "Enter a num:"

Happy Coding :slight_smile:

I adjusted the line of code to print('Encrypted text: '+text). I’m not sure if that is what you were referring to, but still getting it wrong.

yes but recheck that line of code.

‘Encrypted text:singlespace’+ text


results in…

image that space is the issue I guess.

You’ve got this!

we have to leave one single space


I have to say I believe I did only leave one space, but I reset the browser and completely retyped the line of code and it worked! Thanks for the help

1 Like

Great! Keep Going! Good luck :+1:

1 Like

I had the same issue here where I had to refresh before it accepted my answer. This isn’t ideal as it will lead students to believe they are doing something incorrectly when they, in fact, are not…


It had me stomped for hours… The page froze and when I refreshed it, the code worked. Must be some weird glitch or something :thinking: