コード例 #1
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)
コード例 #2
0
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)
コード例 #3
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)
コード例 #4
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))
コード例 #5
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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
0
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')
コード例 #9
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
コード例 #10
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
コード例 #11
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"))
コード例 #12
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
コード例 #13
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
コード例 #14
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
コード例 #15
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
コード例 #16
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()
コード例 #17
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
コード例 #18
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()
コード例 #19
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
コード例 #20
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()
コード例 #21
0
def test_save_successful(test_image, tmp_folder):
    # ARRANGE
    s = Steganography(test_image)
    s.encode("doesnt matter")

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

    # ACT
    s.save(mock_png_path)

    # ASSERT
    assert os.path.exists(mock_png_path)
コード例 #22
0
def test_complete_list_to_complete_gt_from_complete(test_image):
    # ARRANGE
    to_complete = [1, 2, 3, 4]
    from_complete = [4, 5, 6]

    expected_result = [1, 2, 3, 4]

    # ACT
    result = Steganography(test_image)._complete_list(to_complete,
                                                      from_complete)

    # ASSERT
    assert result == expected_result
コード例 #23
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
コード例 #24
0
def test_complete_list_no_missing_elements(test_image):
    # ARRANGE
    to_complete = [1, 2, 3]
    from_complete = [4, 5, 6]

    expected_result = [1, 2, 3]

    # ACT
    result = Steganography(test_image)._complete_list(to_complete,
                                                      from_complete)

    # ASSERT
    assert result == expected_result
コード例 #25
0
def test_path_as_png_if_two_extensions(test_image, tmp_folder):
    # ARRANGE
    mocked_filepath = os.path.join(tmp_folder, "some_targz_file.tar.gz")
    with open(mocked_filepath, "w") as f:
        f.write("")

    expected_result = os.path.join(tmp_folder, "some_targz_file.png")

    # ACT
    result = Steganography(test_image)._path_as_png(mocked_filepath)

    # ASSERT
    assert result == expected_result
コード例 #26
0
def test_path_as_png_if_file_exists_but_no_extension(test_image, tmp_folder):
    # ARRANGE
    mocked_filepath = os.path.join(tmp_folder, "some_file_without_extension")
    with open(mocked_filepath, "w") as f:
        f.write("")

    expected_result = os.path.join(tmp_folder,
                                   "some_file_without_extension.png")

    # ACT
    result = Steganography(test_image)._path_as_png(mocked_filepath)

    # ASSERT
    assert result == expected_result
コード例 #27
0
def test_encode_and_decode_with_path_for_decoding(tmp_folder, test_image,
                                                  random_words):
    # ARRANGE
    for idx, word in enumerate(random_words):
        s = Steganography(test_image)

        # ACT
        s.encode(word)

        tmp_file = os.path.join(tmp_folder, f"image{idx}.jpg")
        s.save(tmp_file)

        result = s.decode(tmp_file.replace("jpg", "png"))

        # ASSERT
        assert result == word
コード例 #28
0
def test_str_to_binary_string(test_image):
    # ARRANGE
    mocked_string = "This is a test string that is being tested in this test."
    expected_result = (
        "01010100011010000110100101110011001000000110100101110011001000000110000100100"
        +
        "000011101000110010101110011011101000010000001110011011101000111001001101001"
        +
        "011011100110011100100000011101000110100001100001011101000010000001101001011"
        +
        "100110010000001100010011001010110100101101110011001110010000001110100011001"
        +
        "010111001101110100011001010110010000100000011010010110111000100000011101000"
        +
        "11010000110100101110011001000000111010001100101011100110111010000101110"
    )

    # ACT
    result = Steganography(test_image)._str_to_binary_string(mocked_string)

    # ASSERT
    assert result == expected_result
コード例 #29
0
def test_binary_string_to_str_if_end_character(test_image):
    # ARRANGE
    # This is a test string that is being tested in this test.\end
    mocked_binary_string = (
        "01010100011010000110100101110011001000000110100101110011001000000110000100100"
        +
        "000011101000110010101110011011101000010000001110011011101000111001001101001"
        +
        "011011100110011100100000011101000110100001100001011101000010000001101001011"
        +
        "100110010000001100010011001010110100101101110011001110010000001110100011001"
        +
        "010111001101110100011001010110010000100000011010010110111000100000011101000"
        +
        "110100001101001011100110010000001110100011001010111001101110100001011100101"
        + "1100011001010110111001100100")
    expected_result = "This is a test string that is being tested in this test."

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

    # ASSERT
    assert result == expected_result
コード例 #30
0
import cv2
import numpy as np
from steganography import Steganography
from tqdm import tqdm

image = cv2.imread('images/container.png')
s = Steganography()

for i in tqdm(range(9)):
    output = s.compress_image(image=image, numberOfBits=i)
    cv2.imwrite(f"images/extracted_images/image using {i} bit.png", output)