task3 #2
@ -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"))
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user