text = 'Hello Zaira'
custom_key = 'python'
def vigenere(message, key, direction):
key_index = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in message.lower():
# Append space to the message
if char == ' ':
encrypted_text += char
else:
# Find the right key character to encode
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)
# User Editable Region
new_index = offset * direction
# User Editable Region
encrypted_text += alphabet[new_index]
return encrypted_text
#encryption = vigenere(text, custom_key)
#print(encryption)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 70
All you need to do is multiply the offset by the direction in the new_index assignment. The multiplication operator in Python is *. i type
new_index = offset * direction
as I understand but the step in not submit
for char in message.lower():
# Append space to the message
if char == ' ':
encrypted_text += char
else:
# Find the right key character to encode
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) % len(alphabet)
encrypted_text += alphabet[new_index]
return encrypted_text
#encryption = vigenere(text, custom_key) #print(encryption)
this is my full code even when I try to fix the problem with your help it still can work and I don’t why so thanks for your help and please if you can find the source of problem because I try many times but without results
hi Teller
it’s still not working I reset the step 70 and I change the original line to thw new one " new_index = offset * direction "
but I have this notification " You should multiply offset by direction in the new_index assignment. Do not add other parentheses."
unfortunately still not working I delete only the expression of index and the sign + and the formule % len( alphabet) but it’s still not working and add " * direction " also I try to
I replace this " new_index = (index + offset) % len(alphabet) "
to this --solution removed--
that what tell me @Teller but I resolve now the problem thanks for your help @ILM and @Teller the solution is --solution removed-- if any one struggle in this step this is the solution
Although I already solved the problem, but I feel most of the hint of the solution in the question page(in the freeCodeCamp) really need to be redefine, it keep making people misunderstanding the requirements, especially for those english is not their main language.