Skip to content

Commit 7975530

Browse files
committed
rotational-cipher: estimate and tidy
1 parent eb87158 commit 7975530

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

‎config.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144

145145
]
146146
},
147+
{
148+
"slug": "rotational-cipher",
149+
"difficulty": 4,
150+
"topics": [
151+
152+
]
153+
},
147154
{
148155
"slug": "kindergarten-garden",
149156
"difficulty": 4,
@@ -538,13 +545,6 @@
538545
"difficulty": 10,
539546
"topics": [
540547

541-
]
542-
},
543-
{
544-
"slug": "rotational-cipher",
545-
"difficulty": 1,
546-
"topics": [
547-
548548
]
549549
}
550550
],

‎exercises/rotational-cipher/src/example/java/RotationalCipher.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
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
}

‎exercises/rotational-cipher/src/test/java/RotationalCipherTest.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
import org.junit.Assert;
3-
import org.junit.Before;
42
import org.junit.Ignore;
53
import 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
}

0 commit comments

Comments
 (0)