Example #1
0
def extractData():
    algo = extractAlgo.get()
    
    if(algo == "Blowfish" or algo == "LSB"):
        raw = lsb.decodeImage(extractInputFile)
        if(algo == "Blowfish"):
            raw = blowfish_algo.decrypt(raw)
    elif(algo == "BPCS"):
        raw = bpcs.decode(extractInputFile, "", alpha)
        
    elif(algo == "DCT"):
        d = DCT(extractInputFile)
        raw = d.DCTDe()
        
    eim=Image.open(extractInputFile)
    eim = eim.resize((100, 75), Image.ANTIALIAS)
    rphoto=ImageTk.PhotoImage(eim)
    
    rightImage['image'] = rphoto
    rphoto.image = rphoto

    print(len(raw))

    if extractContentType.get() == "Plain text":
        extractStatusLbl.configure(text="Success")
        outputTexArea.delete('1.0',"end")
        outputTexArea.insert('1.0', raw)
    elif extractContentType.get() == "File":
        with open(extractToFilename, "wb") as target:
            target.write(raw)
        print(f"Succecfully extracted to: {extractToFilename}")
        
    else:
        raise AssertionError("Invalid extract content type")
Example #2
0
def embedImage():
    algo = variable.get()

    inp = getSecretContent()

    out_f, out_ext = embedInputFile.split(".")
    out_f = out_f + "_"  + algo + ".png"
    fileName = os.path.basename(out_f)
    fileName = outFolder + "/" + fileName
    
    
    if(algo == "LSB"):
        lsb.encodeImage(embedInputFile, inp, fileName)
    elif(algo == "Blowfish"):
        #encrypt the input data
        inp = blowfish_algo.encrypt(inp)
        print(type(inp))
        lsb.encodeImage(embedInputFile, inp, fileName)
    elif(algo == "BPCS"):
        global alpha
        bpcs.encode(embedInputFile, inp, fileName, alpha) 
    
    elif(algo == "DCT"):
        d = DCT(embedInputFile)
        d.DCTEn(inp, fileName)
    
    lim=Image.open(embedInputFile)
    lim = lim.resize((100, 75), Image.ANTIALIAS)
    lphoto=ImageTk.PhotoImage(lim)
    
    inImage['image'] = lphoto
    lphoto.image = lphoto
    
    oim=Image.open(embedInputFile)
    oim = oim.resize((100, 75), Image.ANTIALIAS)
    ophoto=ImageTk.PhotoImage(oim)
    
    emImage['image'] = ophoto
    ophoto.image = ophoto
    
    embedStatusLbl.configure(text="Success")
    print("Embed Success")
Example #3
0
def test_plain_text():
    print('test_plain_text()')
    in_img = "test_imgs/mountain.png"
    msg = b"This is my secret"

    out_img = "mountain_DCT.png"

    en = DCT(in_img)
    en.DCTEn(msg, out_img)

    dec = DCT(out_img)
    secret = dec.DCTDe()

    if secret != msg:
        raise AssertionError("Secret != msg")

    print('Passed!\n')
Example #4
0
def test_embed_img():
    print("test_embed_img()")
    in_img = "test_imgs/river.png"
    with open("test_imgs/face.jpg", "rb") as f:
        raw = f.read()

    out_img = "river_DCT.png"

    en = DCT(in_img)
    en.DCTEn(raw, out_img)

    dec = DCT(out_img)
    secret = dec.DCTDe()

    if secret != raw:
        raise AssertionError("Secret face.jpg != original face.jpg")

    print('Passed!\n')
from dct import DCT

in_img = "test_imgs/mountain.png"
msg = b"This is my secret"

out_img = "mountain_dct.png"

en = DCT(in_img)
en.DCTEn(msg, out_img)

dec = DCT(out_img)
secret = dec.DCTDe().decode()

print(secret)
Example #6
0
def reduce_dimension_function(option, X_train, new_dim):

    if option == 'pca':
        n_batches = 10
        pca = PCA(n_components=new_dim)
        pca.fit(X_train)
        X_reduced = pca.transform(X_train)
        print(np.shape(X_reduced))
        return X_reduced

    elif option == 'autoencoder':
        autoe = AUTOE()
        autoe.set_data(X_train)
        autoe.shuffle_data()
        # autoe.normalize(-1.0, 1.0)
        autoe.divide_data(0.8)
        autoe.create_autoencoder(new_dim)
        # autoe.normalize() # best results of clustering for interval [0, 1]
        # autoe.standardize()
        autoe.train_autoencoder()
        # autoe.test_autoencoder()
        # autoe.get_activations()
        autoe.sort_activations()

        # autoe.plot_reconstruction(i+1)
        # autoe.save_activations('caract_autoe.csv')
        # autoe.save_activations(filename+'_'+str(i+1)+'.csv')
        # autoe.save_activations('caract_autoe.csv')
        return autoe.get_activations()

    elif option == 'svd':
        svd = SVD()
        svd.set_data(X_train)
        # svd.load_data('dataset.csv')
        svd.shuffle_data()
        # svd.normalize(-1.0,1.0)
        # svd.standardize()
        svd.run_svd(new_dim)
        svd.sort_coefficients()
        # svd.save_activations('caract_'+svd.__class__.__name__.lower()+'60.csv')
        # svd.save_activations(filename+'_'+str(i+1)+'.csv')
        return svd.get_coefficients()

    elif option == 'cp':
        cp = CP()
        cp.set_data(X_train)
        # cp.load_data('dataset.csv')
        cp.shuffle_data()
        # cp.normalize(-1.0, 1.0)
        # cp.standardize()
        cp.execute_cp(new_dim)
        cp.sort_coefficients()
        # cp.save_activations(filename+'_'+str(i+1)+'.csv')
        # cp.save_activations('caract_cp.csv')
        return cp.get_coefficients()

    elif option == 'dct':
        dcost = DCT()
        dcost.set_data(X_train)
        dcost.shuffle_data()
        # dcost.normalize(-1.0, 1.0)
        dcost.execute_dct(new_dim)
        dcost.sort_coefficients()
        # dcost.save_activations(filename+'_'+str(i+1)+'.csv')
        # dcost.save_activations('caract_dct.csv')
        return dcost.get_coefficients()

    elif option == 'dwt':
        dwt = DWT()
        dwt.set_data(X_train)
        dwt.shuffle_data()
        # dwt.normalize(-1,1)
        # dwt.standardize()
        dwt.execute_dwt(new_dim)
        dwt.sort_coefficients()
        return dwt.get_coefficients()

    elif option == 'ipla':
        paa = IPLA()
        paa.set_data(X_train)
        # paa.load_data('dataset.csv')
        paa.shuffle_data()
        # paa.normalize()
        # paa.standardize()
        paa.execute_ipla(new_dim)
        paa.sort_coefficients()
        return paa.get_coefficients()

    elif option == 'paa':
        paa = PAA()
        paa.set_data(X_train)
        # paa.load_data('dataset.csv')
        paa.shuffle_data()
        # paa.normalize(-1, 1)
        # paa.standardize()
        paa.execute_paa(new_dim)
        paa.sort_coefficients()
        return paa.get_coefficients()

    elif option == 'sax':
        sax = SAX()
        sax.set_data(X_train)
        sax.shuffle_data()
        # sax.normalize()
        # sax.standardize()
        sax.execute_sax(new_dim)
        sax.sort_coefficients()

        return sax.get_coefficients()

    else:
        return 'Invalid option'
Example #7
0
# Importing the Libraries necessary for the program
import numpy as np
import cv2
import matplotlib.pyplot as plt
import sys
from dct import DCT
from quantization import quantizationClass

dct_Object = DCT()
quantization_Object = quantizationClass()

# This function takes one image channel as the input and returns the
# DCT processed output for the same.
# We use DCT on the Image to convert it from Spectral Domain
# (Y-Cb-Cr Channels) to its equivalent Frequency Domain.


def compressedInformation(Y,
                          N=8,
                          compressionPercentage=50,
                          restrictingFactor=5):
    h, w = Y.shape
    # N, restrictingFactor = 8, 5
    # dctMatrix = generate_N_Point_DCT(N)
    # Q = getQuantizationMatrix(compressionPercentage)
    outArr = np.random.randn(restrictingFactor, restrictingFactor, 1)
    # print(outArr.shape)
    for i in range(0, h - N, N):
        for j in range(0, w - N, N):
            tempImg = Y[i:i + N, j:j + N]
            D = dct_Object.calculateDCT(tempImg)