Exemplo n.º 1
0
    def do_decode_with_clear(self, file_name, encoded_value):
        sys.argv = ['main.py', '-d', '-f', file_name, '-c']
        result = main.run()
        self.assertEqual(encoded_value, result)

        with self.assertRaises(Exception) as cm:
            Steganography.decode_from_bmp(file_name)
        exception = cm.exception
        self.assertEqual(strings.DATA_CORRUPTED, exception.args[0])
Exemplo n.º 2
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])
Exemplo n.º 3
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])
 def decode_from_many_bmp(files):
     """Декодирует сообщение из большого количества файлов"""
     message_list = []
     for file in files:
         message_list.append(Steganography.decode_from_bmp(file))
     return ManySteganographyAdapter._get_message_from_secret_list(
         message_list)
Exemplo n.º 5
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
Exemplo n.º 6
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)