Problem Statement
You have decided to create your own simple encryption method for strings containing only lowercase letters and spaces. You start by splitting the alphabet into two groups. The first group consists of the first firstSize letters of the alphabet, and the second consists of the remaining 26 - firstSize letters. To encrypt a character in your message, you do the following:
- If it a space, it is kept as is.
- If it is a letter in the first group, it is moved firstRotate letters forward in the group, wrapping back to the start if necessary. For example, if firstSize is 6 and firstRotate is 2, then 'A' would become 'C', and 'F' would become 'B'.
- If it is a letter in the second group, then it is moved secondRotate letters forward in the group, again wrapping back to the start of the group if necessary.
Given firstSize, firstRotate, secondRotate and a message, return the encrypted form of the message.
Definition
- Class:
- TwoRotationCypher
- Method:
- encrypt
- Parameters:
- int, int, int, String
- Returns:
- String
- Method signature:
- String encrypt(int firstSize, int firstRotate, int secondRotate, String message)
- (be sure your method is public)
Constraints
- firstSize will be between 1 and 25, inclusive.
- firstRotate will be between 0 and firstSize - 1, inclusive.
- secondRotate will be between 0 and 25 - firstSize, inclusive.
- message will contain between 1 and 50 characters, inclusive.
- message will contain only lowercase letters ('a' - 'z') and spaces.
Examples
13
0
0
"this string will not change at all"
Returns: "this string will not change at all"
13
7
0
"only the letters a to m in this string change"
Returns: "onfy tbl flttlrs h to g cn tbcs strcna jbhnal"
9
0
16
"j to z will change here"
Returns: "z sn y vikk chamge heqe"
17
9
5
"the quick brown fox jumped over the lazy dog"
Returns: "yqn izalc kwgsf ogt bzehnm grnw yqn djvu mgp"
3
1
2
" watch out for strange spacing "
Returns: " ybvaj qwv hqt uvtbpig urbakpi "
12
11
10
"l"
Returns: "k"
4
3
18
"e"
Returns: "w"
12
6
3
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Returns: "gggggggggggggggggggggggggggggggggggggggggggggggggg"
20
19
4
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Returns: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
22
5
1
"nwtd v mjp qxz a lbugs ol f c yr ke i j "
Returns: "sxci e rou vyw f qgdlb tq k h za pj n o "
6
4
18
" x spf d g ouj t lm b v n we k quei r ayc h"
Returns: " v qnd b y msh r jk f t l uc i oscg p ewa z"
24
7
0
" b z vdnxstm y k qbpj wl hg fzia eru o k"
Returns: " i z ekugbct y r xiwq fs on mzph lad v r"
14
5
8
"o lrf wcnpuv z t x ke ij id masz hgy q m "
Returns: "w czk shexqr v p t bj na ni dfov mlu y d "
23
0
2
" u j s aqov et ifk nybmr l ph d n gw c bx"
Returns: " u j s aqov et ifk nxbmr l ph d n gw c bz"
17
12
4
"yjzs kt d qlp moa cb gu x awi i r e n fv"
Returns: "teuw fx p lgk hjm on by s mrd d v q i az"
22
9
3
" xbbc i o a z d t jq vu r hzs kw f m nysg el"
Returns: " wkkl r b j y m g sd ih e qyf tz o v axfp nu"
1
0
10
" noa kjv u yqf x h lfw drc z p tr m ei gbs "
Returns: " xya utg f jbp i r vph ncm k z ec w os qld "
17
16
8
"ice l at yhw nk bp z k jxdruov z qgsz p f"
Returns: "hbd k qs xgv mj ao y j iwcztnu y pfry o e"
17
11
3
"zyxwvutsrqponmlkjihgfedcba"
Returns: "tsrzyxwvukjihgfedcbaqponml"
20
0
0
" ce u i a abdpl t fy n swogqk mh hr vjx "
Returns: " ce u i a abdpl t fy n swogqk mh hr vjx "
1
0
24
" "
Returns: " "
1
0
1
"b"
Returns: "c"
1
0
3
"b"
Returns: "e"
4
3
21
"defining development is a hard task"
Returns: "czehmhmf czuzknolzms hr d gdqc sdrj"
1
0
20
"zyx"
Returns: "uts"
2
1
23
"zzzzzyyyyyxxxxxuuuuuaaaaa"
Returns: "yyyyyxxxxxwwwwwtttttbbbbb"