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
def encode(): file = request.files["file"] message = request.form.get("name") if file.filename != "": extension = file.filename.split(".")[1] filename = "original." + extension file.save(filename) # save file alpha = 0.45 vslfile = filename msgfile = "message.txt" encfile = "encoded.jpeg" bpcs.encode(vslfile, msgfile, encfile, alpha) return send_file("encoded.jpeg", mimetype="image/jpeg") else: return jsonify( {"ERROR": "Please contact the administrator for more information"})
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")
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()
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)
import bpcs alpha = 0.45 vslfile = "image.jpg" msgfile = "message.txt" encfile = "output.jpeg" # msgfile_decoded = "tmp.txt" bpcs.encode(vslfile, msgfile, encfile, alpha) # embed msgfile in vslfile, write to encfile # bpcs.decode(encfile, msgfile_decoded, alpha) # recover message from encfile # app.py from flask import Flask, request, jsonify, render_template, send_file import os import bpcs app = Flask(__name__) @app.route("/encode", methods=["POST"]) def encode(): file = request.files["file"] message = request.form.get("name") if file.filename != "": extension = file.filename.split(".")[1] filename = "original." + extension file.save(filename) # save file alpha = 0.45 vslfile = filename
import sys import numpy as np import bpcs as bp from PIL import Image if len(sys.argv) < 3: print("USAGE: {0} <IPATH> <SPATH>".format(sys.argv[0])) print(" IPATH: image path") print(" SPATH: secret file path") exit(1) IPATH = sys.argv[1] SPATH = sys.argv[2] blocksize = (8, 8) ath = 0.45 # complexity threshold # prepare secret blocks arr = bp.read_message_as_numpy(SPATH, blocksize) arr = bp.to_binary(arr) secret_blocks, conj_map = bp.secret_blocks(arr, blocksize, ath) # encode arr = bp.read_image_as_numpy(IPATH) arr = bp.to_binary(arr) arr = bp.encode(arr, secret_blocks, conj_map, blocksize, ath) arr = bp.to_image(arr) Image.fromarray(np.uint8(arr)).show() Image.fromarray(np.uint8(arr)).save("images/encoded.png")