task3 #2

Merged
schmidmarco merged 40 commits from task3 into main 2026-03-13 10:11:18 +01:00
2 changed files with 24 additions and 4 deletions
Showing only changes of commit 76e5f47d64 - Show all commits

View File

@ -1,9 +1,18 @@
class VigenereCipher(object):
def __init__(self, key, alphabet):
pass
self.key = key
self.alphabet = alphabet
def encode(self, text):
pass
idx_key = [self.alphabet.index(x) for x in self.key]
idx_text = [self.alphabet.index(x) for x in text]
pos_enc = [sum(x) % len(self.alphabet) for x in zip(idx_key, idx_text)]
return "".join([self.alphabet[x] for x in pos_enc])
def decode(self, text):
pass
test = VigenereCipher("password", "abcdefghijklmnopqrstuvwxyz")
print(test.encode("codewars"))

View File

@ -1,5 +1,16 @@
"""from src.codewars.kata_cipher_helper import *
from src.codewars.kata_cipher_helper import VigenereCipher
def test_cipher_helper():
pass"""
abc = "abcdefghijklmnopqrstuvwxyz"
key = "password"
c = VigenereCipher(key, abc)
assert c.encode("codewars") == "rovwsoiv"
assert c.decode("rovwsoiv") == "codewars"
assert c.encode("waffles") == "laxxhsj"
assert c.decode("laxxhsj") == "waffles"
assert c.encode("CODEWARS") == "CODEWARS"
assert c.decode("CODEWARS") == "CODEWARS"