def test_caesar(self): caesar = Caesar() encoded_phrase = caesar.encode(self.phrase) decoded_phrase = caesar.decode(encoded_phrase) print('Caesar: {0} => {1} => {2}'.format(self.phrase, encoded_phrase, decoded_phrase)) self.assertEqual(decoded_phrase, self.phrase)
def encode(self, text, cipher_key): """Use keyword to shift characters by using Caesar""" encoded_text = '' caesar = Caesar() for i in range(0, len(text)): encoded_text += caesar.encode(text[i], ord(cipher_key[(i % len(cipher_key))])) return encoded_text
def encode(self, text, cipher_key): """Use Multiplication, then Caesar""" multiplication = Multiplication() encoded_text = multiplication.encode(text, cipher_key[0]) print('Multiplied: ', encoded_text) caesar = Caesar() encoded_text = caesar.encode(encoded_text, cipher_key[1]) print('Caesared: ', encoded_text) return encoded_text
def do_option(option: int, mode_option: int, text: str, key: str): result = '' if option == 1: rail_fence = RailFence(int(key)) if mode_option == 1: result = rail_fence.encode(text) else: result = rail_fence.decode(text) elif option == 2: viegnere = Viegnere() if mode_option == 1: result = viegnere.encode(text, key) else: result = viegnere.decode(text, key) elif option == 3: matrix = Matrix(key) if mode_option == 1: result = matrix.encode(text) else: result = matrix.decode(text) elif option == 4: caesar = Caesar(int(key)) if mode_option == 1: result = caesar.encode(text) else: result = caesar.decode(text) else: print("Zla opcja!") if result != '': if mode_option == 1: print("Zaszyfrowany tekst: {}".format(result)) else: print("Odszyfrowany tekst: {}".format(result)) return