chore: added kata description. feat: kata rot13, which is a cesar cipher with 13 letter shift. test: test cases for kata rot13.
This commit is contained in:
parent
e1ad5e8296
commit
40c55cd0e5
@ -33,4 +33,5 @@ Repository for CDS-2020 Programming and Promt Engineering II
|
|||||||
|Chinese Numeral Encoder|kata_chinese_numeral_encoder.py|test_chinese_numeral_encoder.py|[52608f5345d4a19bed000b31](https://www.codewars.com/kata/52608f5345d4a19bed000b31)|
|
|Chinese Numeral Encoder|kata_chinese_numeral_encoder.py|test_chinese_numeral_encoder.py|[52608f5345d4a19bed000b31](https://www.codewars.com/kata/52608f5345d4a19bed000b31)|
|
||||||
|RGB To Hex Conversion|kata_rgb_2_hex.py|test_rgb_2_hex.py|[513e08acc600c94f01000001](https://www.codewars.com/kata/513e08acc600c94f01000001)|
|
|RGB To Hex Conversion|kata_rgb_2_hex.py|test_rgb_2_hex.py|[513e08acc600c94f01000001](https://www.codewars.com/kata/513e08acc600c94f01000001)|
|
||||||
|Most frequently used words in a text|kata_most_words_used.py|test_most_words_used.py|[51e056fe544cf36c410000fb](https://www.codewars.com/kata/51e056fe544cf36c410000fb)|
|
|Most frequently used words in a text|kata_most_words_used.py|test_most_words_used.py|[51e056fe544cf36c410000fb](https://www.codewars.com/kata/51e056fe544cf36c410000fb)|
|
||||||
|Simple Fun #128: Doubly Not Less|kata_doubly_not_less.py|test_doubly_not_less.py|[58a3ea0a8bdda5093800000e](https://www.codewars.com/kata/58a3ea0a8bdda5093800000e)|
|
|Simple Fun #128: Doubly Not Less|kata_doubly_not_less.py|test_doubly_not_less.py|[58a3ea0a8bdda5093800000e](https://www.codewars.com/kata/58a3ea0a8bdda5093800000e)|
|
||||||
|
|Rot13|kata_rot13.py|test_rot13.py|[530e15517bc88ac656000716](https://www.codewars.com/kata/530e15517bc88ac656000716/)|
|
||||||
|
|||||||
22
src/codewars/kata_rot13.py
Normal file
22
src/codewars/kata_rot13.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
|
||||||
|
|
||||||
|
def rot13(s):
|
||||||
|
cipher = []
|
||||||
|
|
||||||
|
for c in s:
|
||||||
|
make_upper = c.isupper()
|
||||||
|
c = c.lower()
|
||||||
|
|
||||||
|
if c.isalpha():
|
||||||
|
i = (ALPHABET.index(c) + 13) % 26
|
||||||
|
new_s = ALPHABET[i]
|
||||||
|
|
||||||
|
if make_upper:
|
||||||
|
new_s = new_s.upper()
|
||||||
|
|
||||||
|
cipher.append(new_s)
|
||||||
|
else:
|
||||||
|
cipher.append(c)
|
||||||
|
|
||||||
|
return "".join(cipher)
|
||||||
14
tests/tests_codewars/test_rot13.py
Normal file
14
tests/tests_codewars/test_rot13.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from src.codewars.kata_rot13 import rot13
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("s", "expected"),
|
||||||
|
[
|
||||||
|
("test", "grfg"),
|
||||||
|
("Test", "Grfg"),
|
||||||
|
("aA bB zZ 1234 *!?%", "nN oO mM 1234 *!?%"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_rot13(s, expected):
|
||||||
|
assert rot13(s) == expected
|
||||||
Loading…
x
Reference in New Issue
Block a user