curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6555231eac4d9f19bd3d44b5.md
The pass keyword can be used as a placeholder for future code. It does not have any effect in your code but it can save you from errors you would get in case of incomplete code:
def foo():
pass
Calling vigenere with 1 to encrypt and -1 to decrypt is fine but it might be a little bit cryptic. Create a new function called encrypt that takes message and key parameters, and use pass to fill the function body.
You should declare a new function called encrypt. Remember to use the pass keyword inside the body.
({ test: () => assert(runPython(`
import inspect
inspect.isfunction(encrypt)
`))
})
Your encrypt function should take message and key as the parameters. The order matters.
({ test: () => assert(runPython(`
import inspect
sig = inspect.signature(encrypt)
str(sig) == "(message, key)"
`))
})
text = 'Hello Zaira!'
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
--fcc-editable-region--
encryption = vigenere(text, custom_key)
print(encryption)
decryption = vigenere(encryption, custom_key, -1)
print(decryption)
--fcc-editable-region--