task3 #2

Merged
schmidmarco merged 40 commits from task3 into main 2026-03-13 10:11:18 +01:00
3 changed files with 37 additions and 1 deletions
Showing only changes of commit be6d0997dc - Show all commits

View File

@ -0,0 +1,28 @@
class CaesarCipher(object):
def __init__(self, shift):
self.shift = shift
self.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def encode(self, text):
idx_alph = [
self.alphabet.index(x) if x in self.alphabet else x for x in text.upper()
]
idx_shift = [
(x + self.shift) % len(self.alphabet) if isinstance(x, (int)) else x
for x in idx_alph
]
return "".join(
[self.alphabet[x] if isinstance(x, (int)) else x for x in idx_shift]
)
def decode(self, text):
idx_alph = [
self.alphabet.index(x) if x in self.alphabet else x for x in text.upper()
]
idx_shift = [
(x - self.shift) % len(self.alphabet) if isinstance(x, (int)) else x
for x in idx_alph
]
return "".join(
[self.alphabet[x] if isinstance(x, (int)) else x for x in idx_shift]
)

View File

@ -0,0 +1,8 @@
from src.codewars.kata_ceasar_cipher_helper import CaesarCipher
def test_cipher_helper():
c = CaesarCipher(5)
assert c.encode("Codewars") == "HTIJBFWX"
assert c.decode("HTIJBFWX") == "CODEWARS"

View File

@ -1,4 +1,4 @@
from src.codewars.kata_cipher_helper import VigenereCipher
from src.codewars.kata_vigenere_cipher_helper import VigenereCipher
def test_cipher_helper():