Advertisement
Guest User

Untitled

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