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:
parent
ee9265d00c
commit
76e5f47d64
@ -1,9 +1,18 @@
|
|||||||
class VigenereCipher(object):
|
class VigenereCipher(object):
|
||||||
def __init__(self, key, alphabet):
|
def __init__(self, key, alphabet):
|
||||||
pass
|
self.key = key
|
||||||
|
self.alphabet = alphabet
|
||||||
|
|
||||||
def encode(self, text):
|
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):
|
def decode(self, text):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
test = VigenereCipher("password", "abcdefghijklmnopqrstuvwxyz")
|
||||||
|
|
||||||
|
print(test.encode("codewars"))
|
||||||
|
|||||||
@ -1,5 +1,16 @@
|
|||||||
"""from src.codewars.kata_cipher_helper import *
|
from src.codewars.kata_cipher_helper import VigenereCipher
|
||||||
|
|
||||||
|
|
||||||
def test_cipher_helper():
|
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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user