def _convert_special_byte_arr_to_text(special_byte_arr): """Конвертирует байтовый массив с сообщением обратно в сообщение.""" if not Steganography._check_message_availability(special_byte_arr): raise Exception(strings.DATA_CORRUPTED) encoded_text = special_byte_arr[:-36].decode("UTF-8") decoded_text = Crypter.decode_text(encoded_text) return decoded_text
def _check_message_availability(special_byte_arr): """Проверяет массив байт на наличие сообщения и метаданных.""" try: hash_from_byte_arr = special_byte_arr[-36:-4].decode("UTF-8") encoded_text = special_byte_arr[:-36].decode("UTF-8") decoded_text = Crypter.decode_text(encoded_text) hash_of_decoded_text = Crypter.get_MD5_hash(decoded_text) return hash_of_decoded_text == hash_from_byte_arr except UnicodeDecodeError: raise Exception(strings.DATA_CORRUPTED)
def make_test_backward_compatibility(self, text): text_for_code = text encoded_text = Crypter.encode_text(text_for_code) decoded_text = Crypter.decode_text(encoded_text) self.assertEqual(text_for_code, decoded_text)