feat: encoding works but with only same length text and key and only alphabet values test: added asserts to test

This commit is contained in:
Sandro Zimmermann 2026-03-04 21:23:22 +01:00
parent ee9265d00c
commit 76e5f47d64
2 changed files with 24 additions and 4 deletions

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"