# Activity 6 - Functions

Very well!

You’ve already done a lot of the program!

In this activity we will use functions to group sections of the code.

That’s great! Now, let’s create 2 functions - one to encrypt the message, and the other to decrypt it. For this, we’re going to use code we already had, and we’ll program something new as well.

1. First, declare a function of return type void, just like encrypting, but to decrypt the name. Name this function decrypt().

2. Copy the contents of the encrypt() function into the new decrypt function.

3. In the sum variable, instead of adding, subtract the character of the name and character of the keyword, and add a letter a (instead of subtracting) so that the final character is a letter of the alphabet and not some random character.

4. Change the condition to turn in the alphabet. Instead of checking to see if the sum is greater than the character z, check if the sum is less than a; if so, add 25 to the variable, instead of subtracting.

5. In the main function, call the corresponding function in the if condition depending on if we want to encrypt or decrypt a message.

When you’re done, you can press Run and try the following examples:

programmer
1
reina

witvczxipigrmg
2
reina


You should also try using your own secret words!

Remember that you can always go back to the previous activities to review anything!