def decode(): file = request.files['file_gambar'] img = numpy.fromstring(file.read(), numpy.uint8) im = cv2.imdecode(img, cv2.IMREAD_UNCHANGED) steg = LSBSteg(im) pesan = unicode(steg.decode_text(), "utf8") print(pesan) return render_template("index.html", pesan=pesan)
def test(): if request.method == 'POST': f = request.files['image'] f.save('prof_pic_encoded.png') hash = request.form['hash'].strip() img = LSBSteg(cv2.imread('prof_pic_encoded.png')) txt = img.decode_text() if 'facebook' not in txt or txt == hash: return 'True' else: return 'False'
def forText(): #encoding file = open('abc.txt', 'rb') val = '' val = val + file.read() steg = LSBSteg(cv2.imread("download.jpeg")) img_encoded = steg.encode_text(val) cv2.imwrite("my_new_image.png", img_encoded) #decoding im = cv2.imread("my_new_image.png") steg = LSBSteg(im) print("Text value:", steg.decode_text())
def encode(): if request.method == 'POST': f = request.files['image'] f.save('prof_pic_encoded.png') hash = request.form['hash'].strip() img = LSBSteg(cv2.imread('prof_pic_encoded.png')) txt = img.decode_text() if 'facebook' not in txt or txt == hash: cv2.imwrite('prof_pic_secure.png', img.encode_text(hash)) with open('prof_pic_secure.png', 'rb') as image_file: return base64.b64encode(image_file.read()) else: return 'False'
from LSBSteg import LSBSteg import cv2 #Text encoding: #encoding try: steg = LSBSteg(cv2.imread("original.png")) img_encoded = steg.encode_text("Embedding a secret message, Hello World!") cv2.imwrite("encoded.png", img_encoded) except: # catch *all* exceptions exit(1) #decoding try: im = cv2.imread("encoded.png") steg = LSBSteg(im) print("Text value:", steg.decode_text()) except: # catch *all exceptions exit(2)
def lsbAlgoDefault(encrypt_decrypt, secret_string, encryption_technique): # if (algo_technique == technique_options[0]): # LSB:: Text Steganography if (encrypt_decrypt == options[0]): print("LSB:::Text::: Encrypt") # Warning for secret string if (len(secret_string) == 1): print("Empty Secret:: Showing warning") tk.messagebox.showwarning( "Data Required", "Please enter secret data to be encoded") return # encoding steg = LSBSteg(cv2.imread(image_path)) file_name = encryption_technique + "Plain.txt" text_file = open(file_name, "w") text_file.write(str(secret_string)) text_file.close() if encryption_technique == "OTP": enc = OneTimePad(secret_string, "Plain") enc_string = enc.run(encrypt_decrypt) elif encryption_technique == "RSA": enc = RSACipher(secret_string, "Plain") enc_string = enc.run(encrypt_decrypt) elif encryption_technique == "AES": enc = AESCipher(secret_string, "Plain") enc_string = enc.run(encrypt_decrypt) elif encryption_technique == "DES": enc = DESCipher(secret_string, "Plain") enc_string = enc.run(encrypt_decrypt) img_encoded = steg.encode_text(enc_string) cv2.imwrite("secret/secret.png", img_encoded) displayImage("secret/secret.png") img1 = cv2.imread(image_path) img2 = cv2.imread("secret/secret.png") imgA = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) imgB = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) compare_images(imgA, imgB, "LSB", encryption_technique) else: print("LSB:::Text::: Decrypt") # decoding print(image_path) im = cv2.imread(image_path) steg = LSBSteg(im) secret = steg.decode_text() print("Secret is", secret) if encryption_technique == "OTP": dec = OneTimePad(secret, "Plain") secret_message = dec.run(encrypt_decrypt) elif encryption_technique == "RSA": dec = RSACipher(secret, "Plain") secret_message = dec.run(encrypt_decrypt) elif encryption_technique == "AES": dec = AESCipher(secret, "Plain") secret_message = dec.run(encrypt_decrypt) elif encryption_technique == "DES": dec = DESCipher(secret, "Plain") secret_message = dec.run(encrypt_decrypt) filename = encryption_technique + "Plain.txt" key_file = open(filename, "r") original_message = key_file.readline() key_file.close() precentage_comparison = compare_strings(original_message, secret_message) print("The strings are equal by", precentage_comparison, "parts") addtofile("LSB", encryption_technique[:3], precentage_comparison) #dec = OneTimePad(secret, "Plain") #secret_message = dec.run(encrypt_decrypt) displaySecret(secret_message) print("Text value:", secret_message)