Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CesarCipher(object):
- _alphabet = None
- _shift = None
- def set_alphabet(self, value):
- self._alphabet = value
- def set_shift(self, value):
- self._shift = value
- def encode(self, plainText):
- encode_text = ''
- for item in plainText:
- if item not in self._alphabet:
- encode_text += item
- for i in self._alphabet:
- if item == i:
- index = self.index_of_symbol_in_alphabet(i, self._alphabet)
- encode_text += self._alphabet[index]
- return encode_text
- def index_of_symbol_in_alphabet(self, symbol, alphabet):
- counter = -1
- for i in alphabet:
- counter += 1
- if alphabet[counter] == symbol:
- index = counter + self._shift
- if index >= len(alphabet):
- index = index - len(alphabet)
- return index
- alphabet = 'abcdefghijklmnopqrstuvwxyz'
- plain_text = 'The quick brown fox jumps over the lazy dog'
- task = CesarCipher()
- task.set_alphabet(alphabet)
- task.set_shift(3)
- test = task.encode(plain_text)
- print(test)
Add Comment
Please, Sign In to add comment