-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(6-kyu): kata/simple-rot13-dot-5-cypher (#503)
- Loading branch information
1 parent
b66f2dd
commit e003268
Showing
5 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# [Simple ROT13.5 cypher](https://www.codewars.com/kata/simple-rot13-dot-5-cypher "https://www.codewars.com/kata/5894986e2ddc8f6805000036") | ||
|
||
You are asked to write a simple cypher that rotates every character (in range [a-zA-Z], special chars will be ignored by | ||
the cypher) by 13 chars. As an addition to the original ROT13 cypher, this cypher will also cypher numerical | ||
digits ([0-9]) with 5 chars. | ||
|
||
Example: | ||
|
||
"The quick brown fox jumps over the 2 lazy dogs" | ||
|
||
will be cyphered to: | ||
|
||
"Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf" | ||
|
||
Your task is to write a ROT13.5 (ROT135) method that accepts a string and encrypts it. | ||
Decrypting is performed by using the same method, but by passing the encrypted string again. | ||
|
||
Note: when an empty string is passed, the result is also empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import static java.util.stream.Collectors.joining; | ||
|
||
interface Kata { | ||
static String ROT135(String input) { | ||
return input.chars().mapToObj(c -> "" + (char) c).map(s -> "" + (char) (s.charAt(0) + ( | ||
s.matches("(?i)[A-M]") ? 13 : s.matches("(?i)[N-Z]") ? -13 : | ||
s.matches("[0-4]") ? 5 : s.matches("[5-9]") ? -5 : 0))) | ||
.collect(joining()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
kata/6-kyu/simple-rot13-dot-5-cypher/test/SolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class SolutionTest { | ||
@Test | ||
void sample() { | ||
assertEquals("Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf", Kata.ROT135("The quick brown fox jumps over the 2 lazy dogs")); | ||
assertEquals("The quick brown fox jumps over the 2 lazy dogs", Kata.ROT135("Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf")); | ||
} | ||
} |