SHARE
TWEET

Untitled

a guest Jun 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ScrabbleCipher:
  2.     def __init__(self, keyword):
  3.         self.alpha = string.ascii_uppercase
  4.         self.keyword = keyword.upper()
  5.         self.initialAlpha()
  6.  
  7.     def initialAlpha(self):
  8.         for i in self.keyword:
  9.             self.shuffle(i)
  10.         self.initial = self.alpha
  11.  
  12.  
  13.     def shuffle(self, letter):
  14.         try:
  15.             tg = self.alpha.index(letter)
  16.         except Exception as e:
  17.             print letter
  18.         self.alpha = self.alpha[tg+1:] + letter + self.alpha[:tg]
  19.  
  20.  
  21.     def encrypt(self, plaintext):
  22.         self.alpha = self.initial
  23.         plaintext = plaintext.upper()
  24.         ciphertext = ''
  25.         for i in plaintext:
  26.             pos = string.ascii_uppercase.index(i)
  27.             ciphertext += self.alpha[pos]
  28.             self.shuffle(i)
  29.         return ciphertext
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top