#C6240. Variable Shift Caesar Cipher
Variable Shift Caesar Cipher
Variable Shift Caesar Cipher
You are given a message consisting of lowercase English letters and a sequence of integer shifts. Your task is to implement a variable shift Caesar cipher. When encrypting, each letter in the message is shifted forward in the alphabet by the corresponding shift value modulo 26. When decrypting, the process is reversed, shifting each letter backwards.
The operations are defined as follows:
For a character c at index i and a shift s, the encrypted character is given by:
\(c' = \text{chr}(((\text{ord}(c) - \text{ord}('a') + s) \mod 26) + \text{ord}('a'))\)
Similarly, the decrypted character is obtained by subtracting the shift.
You will be provided with an operation command (encrypt or decrypt), followed by the message and the list of shifts (space-separated) corresponding to each character of the message. It is guaranteed that the number of shifts matches the length of the message.
inputFormat
The input consists of three lines:
- A string which is either "encrypt" or "decrypt" indicating the operation.
- A plaintext message (for encryption) or an encrypted message (for decryption); the message contains only lowercase English letters.
- A sequence of space-separated integers representing the shifts for each character of the message. The number of integers is equal to the length of the message.
outputFormat
Output the resulting string (the encrypted message if the operation is "encrypt"; the decrypted message if the operation is "decrypt").
## sampleencrypt
hello
1 2 3 4 5
igopt