Advertisement
Guest User

Untitled

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