#C7356. Shift Cipher Encryption and Decryption

    ID: 51218 Type: Default 1000ms 256MiB

Shift Cipher Encryption and Decryption

Shift Cipher Encryption and Decryption

This problem involves implementing a simple shift cipher (also known as Caesar cipher) to both encrypt and decrypt messages. Given an operation ('encrypt' or 'decrypt'), a shift value \(k\) (where \(0 \leq k \leq 25\)), and a message consisting of lowercase letters and spaces, you are required to shift each alphabetic character by \(k\) positions. For encryption, the shift is applied forward, and for decryption, it is applied in reverse.

The input will first provide an integer \(T\) which denotes the number of operations. Each of the following \(T\) lines contains an operation, a shift value, and a message. Your program must output the transformed message for each operation on a new line.

inputFormat

The first line of input contains a single integer \(T\) (the number of operations). Each of the next \(T\) lines contains an operation in the following format:

operation k message

where:

  • operation is either encrypt or decrypt.
  • k is an integer (\(0 \leq k \leq 25\)) representing the shift value.
  • message is a string consisting of lowercase letters and spaces.

outputFormat

For each operation, output the resulting message on a separate line. The result is obtained by shifting each letter of the provided message by \(k\) positions to the right for encryption or to the left for decryption.

## sample
2
encrypt 3 hello world
decrypt 3 khoor zruog
khoor zruog

hello world

</p>