Problem Brief

Encrypt

INTERNOA

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 text is within the range [1..100];
  • String text is 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.

1Example 1

Input
text = "PINEAPPLE"
Output
"TMRIETTPI"
Explanation
:O

2Example 2

Input
text = "ZEBRA"
Output
"DIFVE"
Explanation
:3

3Example 3

Input
text = "NETWORK"
Output
"RIXASVO"
Explanation
:/
public String encrypt(String text) {
  // write your code here
}

Input

text

"PINEAPPLE"

Output

"TMRIETTPI"

Sign in to submit your solution.