Problem · String

Encrypt

EasyTeslaINTERNOA

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.

Examples
01 · Example 1
text = "PINEAPPLE"
return = "TMRIETTPI"
:O
02 · Example 2
text = "ZEBRA"
return = "DIFVE"
:3
03 · Example 3
text = "NETWORK"
return = "RIXASVO"
:/
More Tesla problems
drafts saved locally
public String encrypt(String text) {
  // write your code here
}

text"PINEAPPLE"
expected"TMRIETTPI"
sign in to submit