Compare commits

..

No commits in common. "252ff429d2a7d582310b317afd37eafa5fb26acb" and "ee9265d00c1ebe7fd37ddf0f0c8ab91c925f8ab2" have entirely different histories.

2 changed files with 5 additions and 47 deletions

View File

@ -1,40 +1,9 @@
class VigenereCipher(object):
def __init__(self, key, alphabet):
self.key = key
self.alphabet = alphabet
pass
def encode(self, text):
encoded = []
idx_key = 0
for char in text:
if char in self.alphabet:
text_pos = self.alphabet.index(char)
key_char = self.key[idx_key % len(self.key)]
key_pos = self.alphabet.index(key_char)
pos = (text_pos + key_pos) % len(self.alphabet)
encoded.append(self.alphabet[pos])
else:
encoded.append(char)
idx_key += 1
return "".join(encoded)
pass
def decode(self, text):
decoded = []
idx_key = 0
for char in text:
if char in self.alphabet:
text_pos = self.alphabet.index(char)
key_char = self.key[idx_key % len(self.key)]
key_pos = self.alphabet.index(key_char)
pos = (text_pos - key_pos) % len(self.alphabet)
decoded.append(self.alphabet[pos])
else:
decoded.append(char)
idx_key += 1
return "".join(decoded)
pass

View File

@ -1,16 +1,5 @@
from src.codewars.kata_cipher_helper import VigenereCipher
"""from src.codewars.kata_cipher_helper import *
def test_cipher_helper():
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"
pass"""