Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ScrabbleCipher:
- def __init__(self, keyword):
- self.alpha = string.ascii_uppercase
- self.keyword = keyword.upper()
- self.initialAlpha()
- def initialAlpha(self):
- for i in self.keyword:
- self.shuffle(i)
- self.initial = self.alpha
- def shuffle(self, letter):
- try:
- tg = self.alpha.index(letter)
- except Exception as e:
- print letter
- self.alpha = self.alpha[tg+1:] + letter + self.alpha[:tg]
- def encrypt(self, plaintext):
- self.alpha = self.initial
- plaintext = plaintext.upper()
- ciphertext = ''
- for i in plaintext:
- pos = string.ascii_uppercase.index(i)
- ciphertext += self.alpha[pos]
- self.shuffle(i)
- return ciphertext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement