Exemple #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])
Exemple #2
0
    def do_encode_with_delete_previous(self, file_name, encode_value):
        sys.argv = ['main.py', '-e', encode_value, '-f', file_name, '-c']
        result = main.run()
        self.assertEqual(strings.ENCODE_COMPLETE, result)

        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])
Exemple #3
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 delete_message_from_many_bmp(files):
        """Удаляет шифрованное соообщение из списка .bmp файлов при наличии."""
        results = []
        for file in files:
            results.append(Steganography.delete_message_from_bmp(file))

        if strings.MESSAGE_NOT_FOUND in results:
            return strings.SOME_FILE_HAS_NOT_MESSAGE + "\n" + strings.MESSAGE_DELETED
        return strings.MESSAGE_DELETED