def encryptView(): if request.method == 'POST': deletePrevious() f = request.files['image'] filename = f.filename extentionFile = filename.split('.') imgPath = f'./upload/{filename}' password = request.form['password'] message = request.form['message'] outputName = f"./upload/{extentionFile[0]}-encr.png" simpleOutput = f'{extentionFile[0]}-encr.png' if extentionFile[1] in allowedFiles: f.save(imgPath) else: flash('Extensión de archivo no permitida', 'danger') return redirect(url_for('index')) # Encrypting File crypto_steganography = CryptoSteganography(password) crypto_steganography.hide(imgPath, outputName, message) flash('Se guardó correctamente', 'success') return render_template('encrypt.html', outfile=simpleOutput) return render_template('encrypt.html')
def encryption(): global imagepath, filepath domainname = domainentry.get() ip1 = 0 try: ip1 = socket.gethostbyname(domainname) error.config(text="Valid Address") except socket.gaierror: error.config(text="Enter Valid IP Address") x = ipaddress.ip_address(ip1) passwrd = passwordentry.get() #encryption starts # Save the encrypted file inside the image crypto_steganography = CryptoSteganography('My secret password key') crypto_steganography.hide(imagepath, 'encrypted.png', ip1) img = Image.open("encrypted.png") img.save("encrypted.png") #filename = input("File to encrypt: ") filename = "encrypted.png" encrypt1(getKey(passwrd), filename) public_key = [] places = [] with open('public.txt', 'r') as filehandle: places = [ current_place.rstrip() for current_place in filehandle.readlines() ] public_key = [int(i) for i in places] ctext = encrypted(passwrd, public_key) comp.config(text="Cipher Text created") with open('cipher.txt', 'w') as filehandle: filehandle.writelines("%s\n" % place for place in ctext) encrypt.config(state="disabled") filenameentry.config(state="normal")
async def hmm(event): if not event.reply_to_msg_id: await event.reply("Reply to any Image.") return await event.edit("hmm... Hiding Text Inside Image...") sed = await event.get_reply_message() if isinstance(sed.media, MessageMediaPhoto): img = await borg.download_media(sed.media, sedpath) elif "image" in sed.media.document.mime_type.split("/"): img = await borg.download_media(sed.media, sedpath) else: await event.edit("Reply To Image") return text = event.pattern_match.group(1) if not text: await event.edit("No input found! --__--") return crypto_steganography = CryptoSteganography("hell") crypto_steganography.hide(img, "./fridaydevs/stegano.png", text) file_name = "stegano.png" ok = "./fridaydevs/" + file_name await borg.send_file( event.chat_id, ok, force_document=True, allow_cache=False, ) for files in (ok, img): if files and os.path.exists(files): os.remove(files)
def reveal(filename): #s_prime = steg_img.IMG(image_path=filename) #s_prime.extract() crypto_steganography = CryptoSteganography('Elm34lp9mvm43') decrypted_bin = crypto_steganography.retrieve(filename) with open('test.txt.aes', 'wb') as f: f.write(decrypted_bin)
def Main(): a = int(input("Enter choice ")) if (a == 1): public_key, private_key = generate_keyPairs() print("Public: ", public_key) print("Private: ", private_key) with open('public.txt', 'w') as filehandle: filehandle.writelines("%s\n" % place for place in public_key) with open('private.txt', 'w') as filehandle: filehandle.writelines("%s\n" % place for place in private_key) elif (a == 2): ctext = [] private_key = [] with open('cipher.txt', 'r') as filehandle: ctext = [ current_place.rstrip() for current_place in filehandle.readlines() ] with open('private.txt', 'r') as filehandle: private_key = [ current_place.rstrip() for current_place in filehandle.readlines() ] ctext = [int(i) for i in ctext] private_key = [int(i) for i in private_key] password = decrypt(ctext, private_key) filename = input("File to decrypt: ") print(ctext) decrypted(getKey(password), filename) crypto_steganography = CryptoSteganography('My secret password key') secret = crypto_steganography.retrieve('encrypted.png') print("this is ip adress", secret) print("Done.")
def run_st(self): try: Image.open(self.image_file[0]) except: self.pushButton_2.setText("Incorrect file type") return self.password = self.lineEdit_3.text() self.crypto_steganography = CryptoSteganography(self.password) self.secret = self.crypto_steganography.retrieve(self.image_file[0]) if self.secret == None: self.pushButton_6.setText("Incorrect password") else: self.textBrowser.setText("Solved text : " + self.secret) self.pushButton_6.setText("Password is resolved")
def post(self): file = request.files['image'].read() filename = str(time.time_ns()) + '.png' with open(filename, 'wb') as f: f.write(file) imgObj = Image.open(filename) img = np.array(imgObj) res_pywt = pywt.dwt2(img, "haar") file_pi = open('filename_pi.obj', 'wb') pickle.dump(res_pywt, file_pi) enc.encrypt_file('filename_pi.obj') with open('filename_pi.obj' + '.enc', 'rb') as f: encrypted_image = f.read() passcode = request.form['passcode'] crypto_steganography = CryptoSteganography(passcode) # Save the encrypted file inside the image crypto_steganography.hide('img.jpg', 'output_image_file.png', encrypted_image) with open('output_image_file.png', "rb") as output: message = output.read() os.remove('output_image_file.png') img_base64 = base64.b64encode(message) return jsonify({'status': str(img_base64)[2:-1]})
def steganographydecrypt(request): barre = BarreRaccourcie.objects.all() name = 'stegano_decrypt' if request.method == 'POST': form = SteganoForm(request.POST, request.FILES) key = request.POST.get("key") form.save() stegas = Stegano.objects.all() for stega in stegas: picture = stega.picture.name crypto_steganography = CryptoSteganography(str(key)) randomname = random.randint(1, 999999) path = 'media/' + picture secret = crypto_steganography.retrieve(path) directory = 'media/steganography/' for file in os.scandir(directory): if file.name.endswith(".jpg"): os.unlink(file.path) stegas.delete() return render(request, 'steganodecrypt.html', { 'barre': barre, 'name': name, 'message': secret }) else: return render(request, 'steganodecrypt.html', { 'barre': barre, 'name': name })
def test_message(key: str, secret_message: str, expected: str) -> None: crypto_steganography = CryptoSteganography(key) crypto_steganography.hide(INPUT_IMAGE, OUTPUT_IMAGE, secret_message) secret = crypto_steganography.retrieve(OUTPUT_IMAGE) assert secret == expected
def hide(embed, cover): #s = steg_img.IMG(payload_path=embed, image_path=cover) #s.hide() message = None with open(embed, "rb") as f: message = f.read() crypto_steganography = CryptoSteganography('My secret password key') crypto_steganography.hide(cover, 'outfile.png', message)
def encode(): img_path = input("\t Enter IMG path With Extension (ex: img.png) :") op_path = input("\t Enter Output Image Name (ex: opImage): ") + ".png" msg = input("\t Enter msg: ") pswd = input("\t Enter Stegno Pass: "******"Success Fully Save at: "+ op_path + "\n") return main()
def decode(): pswd = input("\t Enter Stegno Pass: "******"\t Enter Stegno File Name (ex: opImage): ") + ".png" steg = CryptoSteganography(pswd) msg = steg.retrieve(ip_path) print("_________________MESSAGE________________\n") print("\t ", msg) print("\n________________________________________\n") return main()
def test_binary_file(key: str, message_file: str) -> None: secret_message = None with open(message_file, 'rb') as f: secret_message = f.read() crypto_steganography = CryptoSteganography(key) crypto_steganography.hide(INPUT_IMAGE, OUTPUT_IMAGE, secret_message) secret = crypto_steganography.retrieve(OUTPUT_IMAGE) assert secret == secret_message
def encode(): inputimg = input('Introduce la dirección de la imagen: ') imgName = inputimg.split('.') outputimg = f"{imgName[0]}-encr.png" separator() password = getpass() message = input('Escribe tu mensaje a ocultar: ') crypto_steganography = CryptoSteganography(password) crypto_steganography.hide(inputimg, outputimg, message) separator() print('Done!')
def decode(): password = getpass() targetImg = input('Introduce la ruta de la imagen: ') separator() crypto_steganography = CryptoSteganography(password) secret = crypto_steganography.retrieve(targetImg) if(secret == None): print('Contraseña incorrecta') else: print('Tu mensaje oculto es: ') separator() print(secret)
def pr(): crypto_steganography = CryptoSteganography(mas) secret = crypto_steganography.retrieve(filename) if secret is None: llaaa = Label(root, text="Sry!!") llaaa.place(x=100, y=230) root.after(3000, root.destroy) else: l = list(secret.split(" ")) sep = we.index(var.get()) llaaa = Label(root, text="Your password: " + l[sep]) llaaa.place(x=100, y=230) root.after(3000, root.destroy)
def post(self): file = request.files['image'].read() passcode = request cipher = AESCipher('mysecretpassword') encrypted = cipher.encrypt(file) decrypted = cipher.decrypt(encrypted) crypto_steganography = CryptoSteganography('My secret password key') # Save the encrypted file inside the image crypto_steganography.hide('img.jpg', 'output_image_file.png', encrypted) with open('output_image_file.png', "rb") as output: message = output.read() os.remove('output_image_file.png') img_base64 = base64.b64encode(message) return jsonify({'status': str(img_base64)[2:-1]})
def insert(): mydb = mysql.connector.connect(host="localhost", user="******", passwd="rishi1008", database="rishi") cursor = mydb.cursor() q1 = "delete from huta" q = "insert into huta values('" + e.get() + "','" + en.get() + "')" cursor.execute(q1) cursor.execute(q) mydb.commit() crypto_steganography = CryptoSteganography(mas) crypto_steganography.hide(filename, 'output_im.png', ent.get()) res_label = Label(root, text="process completed!") res_label.place(x=120, y=300, width=200, height=50) root.after(2000, root.destroy)
def decryptsuccess(): if request.method == 'POST': f = request.files['file'] # filename = "encrypt.png" f.save("decrypt") secret = request.form['secret'] print(secret) crypto_steganography = CryptoSteganography(secret) print(crypto_steganography) print("Before decrypting") decryptsecret = crypto_steganography.retrieve("decrypt") print("After decrypting") print(decryptsecret) # return render_template("decryptsuccess.html", name = decryptsecret) print(type(decryptsecret)) return jsonify(decryptsecret)
def decrypt(): if request.method == 'POST': # check if post has file file = request.files['file'] pswd = request.form['password'] filename = secure_filename(file.filename) filename_d = 'dec_' + filename file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename_d)) time.sleep(10) # Decrypting file and retrieving message decipher = CryptoSteganography(pswd) secret = decipher.retrieve(filename_d) if secret == None: return render_template('incorrect.html') else: return render_template('message.html', secret=secret)
def convert(): if request.method == 'POST': # check if post has file file = request.files['file'] message = request.form['message'] ps = request.form['password'] filename = secure_filename(file.filename) num = random.randint(1, 999) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) crypto_steganography = CryptoSteganography(ps) # Naming the stego file nm = 'stego' + str(num) + '.png' # Encrypting and hiding a message crypto_steganography.hide( os.path.join(app.config['UPLOAD_FOLDER'], filename), nm, message) msg = 'File encrypted successfully.' return render_template('index.html', msg=msg)
def success(): if request.method == 'POST': f = request.files['file'] # filename = ''.join(secrets.choice(string.ascii_lowercase + string.digits) # for i in range(8)) # filename = filename + ".png" filename = "encrypt.png" f.save(f.filename) secret = request.form['secret'] print(secret) message = request.form['message'] print(message) crypto_steganography = CryptoSteganography(secret) crypto_steganography.hide(f.filename, filename, message) # send_file("../"+filename, as_attachment=True) # return render_template("success.html", name = filename) # return send_file("../"+filename, as_attachment=True) return jsonify(filename)
def save_output_image(password: Optional[str], input_image_file: str, message: Optional[bytes], output_image_file: str) -> Optional[str]: """ Save the output image with secret data inside. """ crypto_steganography = CryptoSteganography(password) error = None try: crypto_steganography.hide(input_image_file, output_image_file, message) except FileNotFoundError: error = 'Failed: Input file {} not found.'.format(input_image_file) except OSError as os_error: # It can be invalid file format error = 'Failed: %s' % os_error return error
def test_invalid_key(key: str) -> None: crypto_steganography = CryptoSteganography(key) crypto_steganography.hide(INPUT_IMAGE, OUTPUT_IMAGE, 'test invalid') crypto_steganography = CryptoSteganography('jfffhh') secret = crypto_steganography.retrieve(OUTPUT_IMAGE) assert secret is None
def image_run(self): try: Image.open(self.image_file[0]) except: self.pushButton_2.setText("Incorrect file type") return if self.pushButton_2.text() == "Click for hidden text and image": self.dir = QFileDialog.getExistingDirectory(os.getenv("Desktop")) self.crypto_steganography.hide(self.image_file[0], str(self.dir) + "/output.png", self.text) self.pushButton_2.setText("Image has been indexed") elif self.pushButton_2.text( ) != "Click for hidden text and image" and self.pushButton_2.text( ) != "Select the image": self.text = self.lineEdit.text() self.password = self.lineEdit_2.text() if len(self.text) == 0: self.pushButton_2.setText("Enter the text to be embedded") elif len(self.password) <= 5: self.pushButton_2.setText("Password length >= 6") else: self.crypto_steganography = CryptoSteganography(self.password) self.pushButton_2.setText("Click for hidden text and image")
async def hmm(event): if not event.reply_to_msg_id: await event.reply("Reply to any Image.") return await event.edit("hmm... Searching for Text Inside The Image...") sed = await event.get_reply_message() if isinstance(sed.media, MessageMediaPhoto): img = await borg.download_media(sed.media, sedpath) elif "image" in sed.media.document.mime_type.split("/"): img = await borg.download_media(sed.media, sedpath) else: await event.edit("Reply To Image") return crypto_steganography = CryptoSteganography("hell") secret = crypto_steganography.retrieve(img) await event.edit( f"<b><u>Decrypted Text Successfully</b></u> \n<b>text</b>:- <code>{secret}</code>", parse_mode="HTML", )
def steganography(request): barre = BarreRaccourcie.objects.all() name = 'stegano_encrypt' if request.method == 'POST': form = SteganoForm(request.POST, request.FILES) message = request.POST.get("message") key = request.POST.get("key") form.save() stegas = Stegano.objects.all() #picture = face[0]['picture'] for stega in stegas: picture = stega.picture.name randomname = random.randint(1, 999999) picture = picture.split('/')[1] path = 'media/steganography/' + picture picture = 'media/steganography/results/Encrypt-' + str( randomname) + os.path.splitext(picture)[0] + '.png' im = Image.open(path) output = os.path.splitext(path)[0] + str(randomname) + '.png' im.convert('RGB').save(output, "PNG") crypto_steganography = CryptoSteganography(str(key)) # Save the encrypted file inside the image crypto_steganography.hide(output, picture, str(message)) secret = crypto_steganography.retrieve(picture) directory = 'media/steganography/' for file in os.scandir(directory): if file.name.endswith(".jpg"): os.unlink(file.path) stegas.delete() return render(request, 'stegano.html', { 'barre': barre, 'name': name, 'picture': picture, 'secret': secret }) else: steg = Stegano.objects.all() steg.delete() return render(request, 'stegano.html', {'barre': barre, 'name': name})
def decrypted1(): global filename ctext = [] private_key = [] with open('cipher.txt', 'r') as filehandle: ctext = [ current_place.rstrip() for current_place in filehandle.readlines() ] with open('private.txt', 'r') as filehandle: private_key = [ current_place.rstrip() for current_place in filehandle.readlines() ] ctext = [int(i) for i in ctext] private_key = [int(i) for i in private_key] password = decrypt(ctext, private_key) print(ctext) decrypted(getKey(password), filename) crypto_steganography = CryptoSteganography('My secret password key') secret = crypto_steganography.retrieve('encrypted.png') outputentry.insert(0, secret) print("this is ip adress", secret) print("Done.")
def get_secret_from_image( password: Optional[str], file_path: str) -> Tuple[Optional[bytes], Optional[str]]: """ Get the secret hided inside an image file (if any). """ secret = None error = None crypto_steganography = CryptoSteganography(password) try: secret = crypto_steganography.retrieve(file_path) except FileNotFoundError: error = 'Failed: Input file {} not found.'.format(file_path) except OSError as os_error: # It can be invalid file format error = str(os_error) if not secret and not error: error = 'No valid data found' return (secret, error)
def post(self): file_url = request.form['image_url'] filename = str(time.time_ns()) urllib.request.urlretrieve(file_url, filename + '.png') passcode = request.form['passcode'] crypto_steganography = CryptoSteganography(passcode) decrypted_img = crypto_steganography.retrieve(filename + '.png') with open(filename + '.obj' + '.enc', 'wb') as f: f.write(decrypted_img) enc.decrypt_file(filename + '.obj' + '.enc') file_pi2 = open(filename + '.obj', 'rb') object_pi2 = pickle.load(file_pi2) response = pywt.idwt2(object_pi2, "haar") response = response.astype('uint8') print('hii') res = Image.fromarray(response, "RGBA") res.save(filename + '.png') res.save('123' + '.png') with open(filename + '.png', "rb") as output: message = output.read() img_base64 = base64.b64encode(message) # os.remove(filename+'.png') return jsonify({'status': str(img_base64)[2:-1]})