File tree 4 files changed +34
-0
lines changed 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 39
39
- [ Primes in numbers] ( primes-in-numbers " 54d512e62a5e54c96200019e ")
40
40
- [ Product of consecutive Fib numbers] ( product-of-consecutive-fib-numbers " 5541f58a944b85ce6d00006a ")
41
41
- [ RGB To Hex Conversion] ( rgb-to-hex-conversion " 513e08acc600c94f01000001 ")
42
+ - [ Rot13] ( rot13-1 " 530e15517bc88ac656000716 ")
42
43
- [ ROT13] ( rot13 " 52223df9e8f98c7aa7000062 ")
43
44
- [ Scramblies] ( scramblies " 55c04b4cc56a697bb0000048 ")
44
45
- [ Simple Pig Latin] ( simple-pig-latin " 520b9d2ad5c005041100000f ")
Original file line number Diff line number Diff line change
1
+ # [ Rot13] ( https://www.codewars.com/kata/rot13-1 " https://www.codewars.com/kata/530e15517bc88ac656000716 ")
2
+
3
+ ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example
4
+ of the Caesar cipher.
5
+
6
+ Create a function that takes a string and returns the string ciphered with Rot13.
7
+ If there are numbers or special characters included in the string, they should be returned as they are. Only letters from the latin/english
8
+ alphabet should be shifted, like in the original Rot13 "implementation".
Original file line number Diff line number Diff line change
1
+ import static java .util .stream .Collectors .joining ;
2
+
3
+ interface Kata {
4
+ static String rot13 (String str ) {
5
+ return str .chars ().mapToObj (c -> "" + (char ) c )
6
+ .map (c -> "" + (char ) (c .charAt (0 ) + (c .matches ("(?i)[A-M]" ) ? 13 : c .matches ("(?i)[N-Z]" ) ? -13 : 0 )))
7
+ .collect (joining ());
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2
+
3
+ import org .junit .jupiter .params .ParameterizedTest ;
4
+ import org .junit .jupiter .params .provider .CsvSource ;
5
+
6
+ class SolutionTest {
7
+ @ ParameterizedTest
8
+ @ CsvSource (textBlock = """
9
+ test, grfg
10
+ Test, Grfg
11
+ !@#$, !@#$
12
+ """ )
13
+ void sample (String message , String expected ) {
14
+ assertEquals (expected , Kata .rot13 (message ));
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments