Learn String Manipulation by Building a Cipher - Step 71

Tell us what’s happening:

It says “Update your comments too. Your first comment should say encode/decode and your second comment should say encrypted/decrypted .” I tried every combination but it gives error and I can not submit it. So I can not continue to the next steps. It is step 71. If anybody did this before or have any suggestions please let me know.

Your code so far


/* User Editable Region */

text = 'Hello Zaira'
custom_key = 'python'

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

    for char in message.lower():
    
        # Append space to the message
        if char == ' ':
            final_message += char
        else:        
            # encode/decode
            key_char = key[key_index % len(key)]
            key_index += 1

            # Define the offset and the encrypted 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
    
encryption = vigenere(text, custom_key, 1)
print(encryption)
decryption = vigenere(encryption, custom_key, -1)
#encrypted/decrypted
print(decryption)

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 71

Your second comment should be Find the right key character to encode/decode
Your third comment should be Define the offset and the encrypted/decrypted letter

1 Like

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