Encrypt
A Caesar cipher encrypts a word by replacing each letter with another letter that is a fixed number of positions after it in the alphabet.
For example, for a cipher that replaces a letter with one that is four letters after it in the alphabet, letter A is replaced by E, letter B is replaced by F, ..., letter Y is replaced by C and letter Z is replaced by D. In other words, each letter in the alphabet is rotated to the right by four positions. For example: PINEAPPLE is encrypted as TMRIETTPI.
The table below shows the mapping of letters when using a Caesar cipher with a rotation of 4.
Write a function:
class Solution { public String encrypt(String text); }
that, given a string text, returns the string encrypted using a Caesar cipher with a rotation of 4.
Assume that:
- The length of string
textis within the range [1..100]; - String
textis made only of uppercase letters (A-Z).
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.