Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. class VigenereSolver:
  2.     dictionary = None
  3.    
  4.     def __init__(self, dictionary:str):
  5.         self.dictionary = dictionary
  6.        
  7.     def encode(self, text:str, key:str) -> str:
  8.         cypher = ""
  9.         for i in range(len(text)):
  10.             key_letter = key[i % len(key)]
  11.             cypher += self.dictionary[(self.dictionary.find(key_letter) + self.dictionary.find(text[i])) % len(self.dictionary)]
  12.        
  13.         return cypher
  14.  
  15.     def decode(self, cypher:str, key: str) -> str:
  16.         text = ""
  17.         for i in range(len(cypher)):
  18.             text += self.dictionary[(len(self.dictionary) + self.dictionary.find(cypher[i]) - self.dictionary.find(key[i % len(key)])) % len(self.dictionary)]
  19.        
  20.         return text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement