Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class VigenereSolver:
- dictionary = None
- def __init__(self, dictionary:str):
- self.dictionary = dictionary
- def encode(self, text:str, key:str) -> str:
- cypher = ""
- for i in range(len(text)):
- key_letter = key[i % len(key)]
- cypher += self.dictionary[(self.dictionary.find(key_letter) + self.dictionary.find(text[i])) % len(self.dictionary)]
- return cypher
- def decode(self, cypher:str, key: str) -> str:
- text = ""
- for i in range(len(cypher)):
- text += self.dictionary[(len(self.dictionary) + self.dictionary.find(cypher[i]) - self.dictionary.find(key[i % len(key)])) % len(self.dictionary)]
- return text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement