String Encryption Problem 2

We are to create an encryption function. It will implement a substitution cypher. For simplicity, it assumes that the string it is encoding is all lowercase letters or spaces. It takes a source string, a destination string and a key.

Inputs

The main() gets a string as input from the user and a key. It passes these to the encryption function and prints the encrypted and clear strings.

Outputs

The initial string is printed and so is the encrypted version.

Notes

A substitution cypher is a very simple code. It is often invented by young children. The key is a small number that is used as an offset into the alphabet. A new string is created to hold the encrypted text. If the encoded character is not in the range of the alphabet, we wrap around to the beginning of the alphabet. Whitespace is unchanged. A couple of examples:
Key is 3
a --> d
b --> e
c --> f
...
w --> z
x --> a
y --> b
z --> c

Answer

Here is one solution to this problem.