Esempio n. 1
0
    def check_delete_mes(self, file_name):
        Steganography.encode_to_bmp(file_name, "Some text")
        coded_text = Steganography.decode_from_bmp(file_name)
        self.assertEqual("Some text", coded_text)
        Steganography.delete_message_from_bmp(file_name)

        with self.assertRaises(Exception) as cm:
            Steganography.decode_from_bmp(file_name)
        exception = cm.exception
        self.assertEqual(strings.DATA_CORRUPTED, exception.args[0])
Esempio n. 2
0
def run():
    parser = create_parser()
    namespace = parser.parse_args(sys.argv[1:])
    many_files = False

    if len(namespace.filepath.split()) != 1:
        many_files = True
        namespace.filepath = namespace.filepath.split()

    if not many_files:
        if namespace.encode is not None and not namespace.decode:
            if namespace.clear:
                Steganography.delete_message_from_bmp(namespace.filepath)
            Steganography.encode_to_bmp(namespace.filepath, namespace.encode)
            return strings.ENCODE_COMPLETE

        elif namespace.decode and namespace.encode is None:
            message = Steganography.decode_from_bmp(namespace.filepath)
            if namespace.clear:
                Steganography.delete_message_from_bmp(namespace.filepath)
            return message

        elif (namespace.clear and namespace.encode is None
              and not namespace.decode):
            return Steganography.delete_message_from_bmp(namespace.filepath)
        else:
            return strings.WRONG_ARGUMENTS
    else:
        if namespace.encode is not None and not namespace.decode:
            if namespace.clear:
                ManySteganographyAdapter.delete_message_from_many_bmp(
                    namespace.filepath)
            ManySteganographyAdapter.encode_to_many_bmp(
                namespace.encode, namespace.filepath)
            return strings.ENCODE_COMPLETE

        elif namespace.decode and namespace.encode is None:
            message = ManySteganographyAdapter.decode_from_many_bmp(
                namespace.filepath)
            if namespace.clear:
                ManySteganographyAdapter.delete_message_from_many_bmp(
                    namespace.filepath)
            return message

        elif (namespace.clear and namespace.encode is None
              and not namespace.decode):
            return ManySteganographyAdapter.delete_message_from_many_bmp(
                namespace.filepath)
        else:
            return strings.WRONG_ARGUMENTS
    def encode_to_many_bmp(message, files):
        """Кодирует сообщение в большое количество файлов"""

        for file in files:
            c = 0
            for i in range(len(files)):
                if files[i] == file:
                    c += 1
            if c > 1:
                raise AttributeError(strings.FILES_IN_PATH_REPEATED)

        message_list = ManySteganographyAdapter._get_secret_list_from_message(
            message, len(files))
        for i in range(len(files)):
            Steganography.encode_to_bmp(files[i], message_list[i])
Esempio n. 4
0
 def check_file_code_decode(self, file_path):
     Steganography.encode_to_bmp(file_path, "Code")
     result = Steganography.decode_from_bmp((file_path))
     self.assertEqual("Code", result)