Example #1
0
def ExtractPayload(file, option, alpha, message=None):
    if option == 1:
        # output = open("decoded_message.txt", "x")

        bpcs.decode(file, "decoded_message.txt", alpha)
        with open('decoded_message.txt') as file:
            data = str(file.read())
            return data
        # decodedoutput.insert(tk.END, data)
    elif option == 2 and message is not None:
        pic = "encoded_file.png"  # +file.split('.')[1]
        bpcs.encode(file, message, pic, alpha)
    else:
        print("Invalid Option")
    return None
Example #2
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 #3
0
def decode():
    file = request.files["file"]
    if file.filename != "":
        extension = file.filename.split(".")[1]
        filename = "encoded." + extension

        file.save(filename)  # save file
        alpha = 0.45
        vslfile = filename
        msgfile = "message.txt"
        encfile = filename
        bpcs.decode(encfile, msgfile, alpha)

        with open(msgfile, "r") as file:
            data = file.read().replace("\n", "")
            return jsonify({"MESSAGE": data})
    else:
        return jsonify(
            {"ERROR": "Please contact the administrator for more information"})
Example #4
0
    def StartDecrypt(self):
        alpha = 0.45
        vslfile = 'C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/vessel.png'
        msgfile = 'C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/message.txt'  # can be any type of file
        encfile = 'C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/encoded.png'
        msgfile_decoded = 'C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/tmp.txt'

        #bpcs.capacity(vslfile, alpha) # check max size of message you can embed in vslfile
        #img = cv2.imread('C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/payload.png')
        #img3 = cv2.imread('C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/vessel.png')
        #vslfile = cv2.imencode('.png', img3)[1].tobytes()
        #type(vslfile)
        #msgfile = cv2.imencode('.png', img)[1].tobytes()
        #type(msgfile)
        bpcs.encode(vslfile, msgfile, encfile,
                    alpha)  # embed msgfile in vslfile, write to encfile
        bpcs.decode(encfile, msgfile_decoded,
                    alpha)  # recover message from encfile

        path = "C:/Users/areev/OneDrive/Documents/GitHub/bpcs/examples/"

        imgpath1 = path + "vessel.png"
        imgpath2 = path + "encoded.png"

        img1 = cv2.imread(imgpath1, 1)
        img2 = cv2.imread(imgpath2, 1)

        img1 = cv2.cvtColor(img1, cv2.COLOR_RGB2BGR)
        img2 = cv2.cvtColor(img2, cv2.COLOR_RGB2BGR)

        titles = ['Cover Image', 'Stego Object']
        images = [img1, img2]

        for i in range(2):
            plt.subplot(1, 2, i + 1)
            plt.imshow(images[i])
            plt.title(titles[i])
            plt.xticks([])
            plt.yticks([])
        plt.show()
Example #5
0
import bpcs

alpha = 0.45
vslfile = 'Temp\\raw_image1.png'
msgfile = 'AnyTextGreaterThan300Chars' # can be any type of file
encfile = 'Temp\\raw_image1_test_bpcs.png'
msgfile_decoded = 'Temp\\tmp.txt'

bpcs.encode(vslfile, msgfile, encfile, alpha) # embed msgfile in vslfile, write to encfile
msg = bpcs.decode(encfile, msgfile_decoded, alpha) # recover message from encfile
print(msg)
Example #6
0
import sys
import numpy as np
import bpcs as bp

from PIL import Image

if len(sys.argv) < 2:
    print("USAGE: {0} <PATH>".format(sys.argv[0]))
    print("    PATH:  encoded image path")
    exit(1)

PATH = sys.argv[1]

blocksize = (8, 8)
ath = 0.45  # complexity threshold

arr = bp.read_image_as_numpy(PATH)
arr = bp.to_binary(arr)
decoded = bp.decode(arr, blocksize, ath)
print("[decoded code]")
print(decoded)