File tree Expand file tree Collapse file tree
exercises/rotational-cipher/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 144144
145145 ]
146146 },
147+ {
148+ "slug" : " rotational-cipher" ,
149+ "difficulty" : 4 ,
150+ "topics" : [
151+
152+ ]
153+ },
147154 {
148155 "slug" : " kindergarten-garden" ,
149156 "difficulty" : 4 ,
538545 "difficulty" : 10 ,
539546 "topics" : [
540547
541- ]
542- },
543- {
544- "slug" : " rotational-cipher" ,
545- "difficulty" : 1 ,
546- "topics" : [
547-
548548 ]
549549 }
550550 ],
Original file line number Diff line number Diff line change 1+ class RotationalCipher {
12
2- public class RotationalCipher {
3-
4- int shiftKey ;
3+ private int shiftKey ;
54
65 RotationalCipher (int shiftKey ) {
76 this .shiftKey = shiftKey ;
87 }
98
10- public String rotate (String data ) {
9+ String rotate (String data ) {
1110 StringBuilder dataStringBuilder = new StringBuilder ();
1211 for (char c : data .toCharArray ()) {
1312 if (Character .isUpperCase (c )) {
@@ -25,12 +24,10 @@ public String rotate(String data) {
2524 * For Uppercase CaseStart = 'A' and CaseEnd = 'Z'
2625 * For Lowercase CaseStart = 'a' and CaseEnd = 'z'
2726 */
28- private char getReplacementCharacter (char characterToReplace ,
29- char alphabetCaseStart , char alphabetCaseEnd ) {
27+ private char getReplacementCharacter (char characterToReplace , char alphabetCaseStart , char alphabetCaseEnd ) {
3028 char replacementCharacter = (char ) (characterToReplace + shiftKey );
3129 if (replacementCharacter > alphabetCaseEnd ) {
32- replacementCharacter = (char ) ((alphabetCaseStart - 1 ) +
33- (replacementCharacter % alphabetCaseEnd ));
30+ replacementCharacter = (char ) ((alphabetCaseStart - 1 ) + (replacementCharacter % alphabetCaseEnd ));
3431 }
3532 return replacementCharacter ;
3633 }
Original file line number Diff line number Diff line change 1-
21import org .junit .Assert ;
3- import org .junit .Before ;
42import org .junit .Ignore ;
53import org .junit .Test ;
64
@@ -13,7 +11,7 @@ public void rotateSingleCharacterBy1() {
1311 rotationalCipher = new RotationalCipher (1 );
1412 Assert .assertEquals ("b" , rotationalCipher .rotate ("a" ));
1513 }
16-
14+
1715 @ Ignore ("Remove to run test" )
1816 @ Test
1917 public void rotateSingleCharacterBy26 () {
@@ -75,7 +73,6 @@ public void rotatePunctuation() {
7573 public void rotateAllLetters () {
7674 rotationalCipher = new RotationalCipher (13 );
7775 Assert .assertEquals ("The quick brown fox jumps over the lazy dog." ,
78- rotationalCipher .rotate ("Gur dhvpx oebja sbk whzcf bire gur ynml qbt." ));
79- }
80-
76+ rotationalCipher .rotate ("Gur dhvpx oebja sbk whzcf bire gur ynml qbt." ));
77+ }
8178}
You can’t perform that action at this time.
0 commit comments