Exemplo n.º 1
0
 def make_test_backward_compatibility(self, message):
     for i in range(1, 10):
         secret_list = Steganography._get_secret_list_from_message(
             message, i)
         result_message = Steganography._get_message_from_secret_list(
             secret_list)
         self.assertEqual(message, result_message)
Exemplo n.º 2
0
def stegano():
    print(request.method)
    path = "cat.jpg"
    output_path = "catencodes.jpg"
    text = request.data
    Steganography.encode(path, output_path, text)
    return send_file(output_path, mimetype='image/jpeg')
def encrypter(fname):
	tools.empty_folder('./encrypted/' + fname + '/files/' )
	tools.empty_folder('./key/')
	key_1 = Fernet.generate_key()
	key_1_1 = Fernet.generate_key()
	key_1_2 = Fernet.generate_key()
	key_2 = ChaCha20Poly1305.generate_key()
	key_3 = AESGCM.generate_key(bit_length=128)
	key_4 = AESCCM.generate_key(bit_length=128)
	nonce13 = os.urandom(13)
	nonce12 = os.urandom(12)
	files = sorted(tools.list_dir('files'))
	for index in range(0,len(files)):
		if index%4 == 0:
			Algo1_extented(files[index],key_1_1,key_1_2, fname)
		elif index%4 == 1:
			Algo2(files[index],key_2,nonce12, fname)
		elif index%4 == 2:
			Algo3(files[index],key_3,nonce12, fname)
		else:
			Algo4(files[index],key_4,nonce13, fname)
	secret_information = (key_1_1)+":::::"+(key_1_2)+":::::"+(key_2)+":::::"+(key_3)+":::::"+(key_4)+":::::"+(nonce12)+":::::"+(nonce13)
	Algo1(secret_information,key_1, fname)

	# Static path to the image file for Steganography
	in_f = "./static/png.png"
	#out_f = './encrypted/' + fname + '/key/'  + fname + '.png'
	out_f = './key/'  + fname + '.png'
	in_img = cv2.imread(in_f)
	steg = Steganography(in_img)

	res = steg.encode_binary(key_1)
	cv2.imwrite(out_f, res)

	tools.empty_folder('files')
def decrypter(Fname):
	tools.empty_folder('files')
	tools.empty_folder('./key_pem')
	list_directory = tools.list_dir('key')
	filename = './key/' + list_directory[0]
	in_f = filename
	out_f = "./key_pem/" + Fname +".pem"
	in_img = cv2.imread(in_f)
	steg = Steganography(in_img)
	key_1 = steg.decode_binary()

	secret_information = Algo1(key_1, Fname)
	list_information = secret_information.split(':::::')
	key_1_1 = list_information[0]
	key_1_2 = list_information[1]
	key_2 = list_information[2]
	key_3 = list_information[3]
	key_4 = list_information[4]
	nonce12 = list_information[5]
	nonce13 = list_information[6]
	files = sorted(tools.list_dir('./encrypted/' + Fname + '/files'))
	for index in range(0,len(files)):
		if index%4 == 0:
			Also1_RSA(files[index],key_1_1,key_1_2, Fname)
		elif index%4 == 1:
			Also2_TrippleDES(files[index],key_2,nonce12, Fname)
		elif index%4 == 2:
			Algo3(files[index],key_3,nonce12, Fname)
		else:
			Algo4(files[index],key_4,nonce13, Fname)
Exemplo n.º 5
0
def hide_message():
    message = request.form['message']
    image = request.files['image']
    steg = Steganography()
    data = bytearray(image.read())
    steg.hide_message(data, message)
    return send_file(io.BytesIO(data))
Exemplo n.º 6
0
def extrac_message():
    steg = Steganography()
    image = request.files['image']
    data = bytearray(image.read())
    arr = steg.extract_message(data)
    message = arr.decode()
    print(message)
    return message
Exemplo n.º 7
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.º 8
0
def decrypt_image(hidden, root):
    steg_var = Steganography()
    cypher = cv2.imread(hidden)
    decyphered_image = steg_var.decrypt_image(cypher)
    filename = './decrypted_images/' + time.strftime("%Y%m%d-%H%M%S") + '.jpg'
    cv2.imwrite(filename, decyphered_image)
    result_str = 'File saved at \"{}\"'.format(filename)
    messagebox.showinfo('SUCCESS!!!', result_str)
    cv2.imshow('Decrypted image', decyphered_image)
    cv2.waitKey()
Exemplo n.º 9
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])
Exemplo n.º 10
0
def test_encode_and_decode_without_path_for_decoding(test_image, random_words):
    # ARRANGE
    for word in random_words:
        s = Steganography(test_image)

        # ACT
        s.encode(word)
        result = s.decode()

        # ASSERT
        assert result == word
Exemplo n.º 11
0
def encrypt_image(message, mask, root):
    steg_var = Steganography()
    mask_img = cv2.imread(mask)
    secret_message_img = cv2.imread(message)
    cypher = steg_var.embed_a_in_b(secret_message_img, mask_img)
    filename = './encrypted_images/' + time.strftime("%Y%m%d-%H%M%S") + '.jpg'
    cv2.imwrite(filename, cypher)
    result_str = 'File saved at \"{}\"'.format(filename)
    messagebox.showinfo('SUCCESS!!!', result_str)
    cv2.imshow('cypher image', cypher)
    cv2.waitKey()
Exemplo n.º 12
0
def test_save_not_successful(test_image, tmp_folder):
    # ARRANGE
    s = Steganography(test_image)

    mock_png_path = os.path.join(tmp_folder, "save_not_sucessful.png")
    s._path_as_png = MagicMock()

    # ACT
    s.save(mock_png_path)

    # ASSERT
    assert not os.path.exists(mock_png_path)
    s._path_as_png.assert_not_called()
    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])
Exemplo n.º 14
0
def normal():
        container = args.image
        mode = args.mode
        try:
            steg = Steganography(container)
            if mode == "hide":
                if args.in_file:
                    information = open(args.in_file, 'rb').read()
                else:
                    information = input("Enter concealed text:\n")
                steg.hide_information(information, args.out_file)
            elif mode == "unhide":
                steg.unhide_information(args.out_file)
        except Exception as e:
            sys.exit("Error: {0}".format(e))
Exemplo n.º 15
0
def test_path_as_png_if_empty_path(test_image):
    # ARRANGE
    mocked_filepath = ""

    # ACT / ASSERT
    with pytest.raises(ValueError):
        Steganography(test_image)._path_as_png(mocked_filepath)
Exemplo n.º 16
0
def test_path_as_png_when_path_does_not_exist_and_is_directory(test_image):
    # ARRANGE
    mocked_filepath = "/some/path/"

    # ACT / ASSERT
    with pytest.raises(IsADirectoryError):
        Steganography(test_image)._path_as_png(mocked_filepath)
Exemplo n.º 17
0
def test_binary_to_rgb_if_invalid_arguments(test_image):
    # ARRANGE
    mocked_binary_rgb = ["01111011", "00000001"]

    # ACT / ASSERT
    with pytest.raises(ValueError):
        Steganography(test_image)._binary_to_rgb(*mocked_binary_rgb)
Exemplo n.º 18
0
def test_str_to_binary_string_if_no_text_passed(test_image):
    # ARRANGE
    mocked_string = ""

    # ACT / ASSERT
    with pytest.raises(ValueError):
        Steganography(test_image)._str_to_binary_string(mocked_string)
Exemplo n.º 19
0
def test_rgb_to_binary_if_invalid_rgb_length(test_image):
    # ARRANGE
    mocked_rgb = (123, 1)

    # ACT / ASSERT
    with pytest.raises(ValueError):
        Steganography(test_image)._rgb_to_binary(mocked_rgb)
Exemplo n.º 20
0
def test_binary_string_to_str_if_end_character_and_text_after(test_image):
    # ARRANGE
    # This is a test string.\endNOW SOME CHARACTERS THAT SHOULD NOT BE SEEN
    mocked_binary_string = (
        "01010100011010000110100101110011001000000110100101110011001000000110000100100"
        +
        "000011101000110010101110011011101000010000001110011011101000111001001101001"
        +
        "011011100110011100101110010111000110010101101110011001000100111001001111010"
        +
        "101110010000001010011010011110100110101000101001000000100001101001000010000"
        +
        "010101001001000001010000110101010001000101010100100101001100100000010101000"
        +
        "100100001000001010101000010000001010011010010000100111101010101010011000100"
        +
        "010000100000010011100100111101010100001000000100001001000101001000000101001"
        + "1010001010100010101001110")
    expected_result = "This is a test string."

    # ACT
    result = Steganography(test_image)._binary_string_to_str(
        mocked_binary_string, r"\end")

    # ASSERT
    assert result == expected_result
 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)
    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
Exemplo n.º 23
0
def test_split_every_3_characters_with_12_characters(test_image):
    # ARRANGE
    mocked_string_to_split = "000111222333444"
    expected_result = ["000", "111", "222", "333", "444"]

    # ACT
    result = Steganography(test_image)._split(mocked_string_to_split, 3)

    # ASSERT
    assert result == expected_result
Exemplo n.º 24
0
def test_split_every_3_characters_with_7_characters(test_image):
    # ARRANGE
    mocked_string_to_split = "1234567"
    expected_result = ["123", "456", "7"]

    # ACT
    result = Steganography(test_image)._split(mocked_string_to_split, 3)

    # ASSERT
    assert result == expected_result
Exemplo n.º 25
0
def test_binary_to_rgb(test_image):
    # ARRANGE
    mocked_binary_rgb = ("01111011", "00000001", "00100000")
    expected_result = (123, 1, 32)

    # ACT
    result = Steganography(test_image)._binary_to_rgb(mocked_binary_rgb)

    # ASSERT
    assert result == expected_result
Exemplo n.º 26
0
def test_binary_to_rgb_if_unpacking(test_image):
    # ARRANGE
    mocked_binary_rgb = ["01111011", "00000001", "00100000"]
    expected_result = (123, 1, 32)

    # ACT
    result = Steganography(test_image)._binary_to_rgb(*mocked_binary_rgb)

    # ASSERT
    assert result == expected_result
Exemplo n.º 27
0
def main():
    path = "examples/apyr.jpg"
    path = os.path.abspath(path)
    s = Steganography(path)

    s.encode("Sample text")
    s.save("examples/apyr - encoded.jpg")

    print(s.decode("examples/apyr - encoded.png"))
Exemplo n.º 28
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.º 29
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.º 30
0
def test_write_to_lsb(test_image):
    # ARRANGE
    mocked_tribit = "110"
    mocked_rgb_binary = ("10000000", "10000000", "10000000")

    expected_result = ["10000001", "10000001", "10000000"]

    # ACT
    result = Steganography(test_image)._write_to_lsb(mocked_tribit,
                                                     mocked_rgb_binary)

    # ASSERT
    assert result == expected_result
Exemplo n.º 31
0
def test_path_as_png_when_path_does_not_exist_and_could_be_file_or_directory(
        test_image, capfd):
    # ARRANGE
    mocked_filepath = "/some/path"
    expected_result = "/some/path.png"

    # ACT
    result = Steganography(test_image)._path_as_png(mocked_filepath)
    output, _ = capfd.readouterr()

    # ASSERT
    assert result == expected_result
    assert "Assuming it's a file" in output
Exemplo n.º 32
0
def test():
    lever = Steganography.test()
    if not lever:
        print("Test is passed")
    else:
        print("Test fails")