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 204204
205205 ]
206206 },
207+ {
208+ "uuid" : " 9eb41883-55ef-4681-b5ac-5c2259302772" ,
209+ "slug" : " rotational-cipher" ,
210+ "core" : false ,
211+ "unlocked_by" : null ,
212+ "difficulty" : 4 ,
213+ "topics" : [
214+
215+ ]
216+ },
207217 {
208218 "uuid" : " 0b92ffee-c092-4ab1-ad78-76c8cf80e1b5" ,
209219 "slug" : " kindergarten-garden" ,
768778
769779 ]
770780 },
771- {
772- "uuid" : " 9eb41883-55ef-4681-b5ac-5c2259302772" ,
773- "slug" : " rotational-cipher" ,
774- "core" : false ,
775- "unlocked_by" : null ,
776- "difficulty" : 1 ,
777- "topics" : [
778-
779- ]
780- },
781781 {
782782 "uuid" : " e58c29d2-80a7-40ef-bed0-4a184ae35f34" ,
783783 "slug" : " accumulate" ,
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