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 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')
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 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")
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 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 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 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 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 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 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})
class Ui_Dialog(object): def __init__(self, a): self.a = a def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(666, 421) self.tabWidget = QtWidgets.QTabWidget(Dialog) self.tabWidget.setGeometry(QtCore.QRect(10, 10, 641, 401)) self.tabWidget.setObjectName("tabWidget") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.pushButton = QtWidgets.QPushButton(self.tab) self.pushButton.setGeometry(QtCore.QRect(160, 90, 321, 41)) font = QtGui.QFont() font.setPointSize(14) font.setBold(False) font.setItalic(True) font.setWeight(50) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.pushButton_3 = QtWidgets.QPushButton(self.tab) self.pushButton_3.setGeometry(QtCore.QRect(540, 330, 91, 31)) self.pushButton_3.setObjectName("pushButton_3") self.label = QtWidgets.QLabel(self.tab) self.label.setGeometry(QtCore.QRect(160, 160, 151, 21)) font = QtGui.QFont() font.setPointSize(13) font.setItalic(True) self.label.setFont(font) self.label.setObjectName("label") self.pushButton_2 = QtWidgets.QPushButton(self.tab) self.pushButton_2.setGeometry(QtCore.QRect(160, 250, 321, 41)) font = QtGui.QFont() font.setPointSize(15) font.setItalic(True) self.pushButton_2.setFont(font) self.pushButton_2.setObjectName("pushButton_2") self.label_2 = QtWidgets.QLabel(self.tab) self.label_2.setGeometry(QtCore.QRect(150, 10, 341, 41)) font = QtGui.QFont() font.setFamily("Century Schoolbook L") font.setPointSize(12) font.setBold(True) font.setItalic(True) font.setWeight(75) self.label_2.setFont(font) self.label_2.setMouseTracking(False) self.label_2.setLayoutDirection(QtCore.Qt.LeftToRight) self.label_2.setAutoFillBackground(False) self.label_2.setTextFormat(QtCore.Qt.AutoText) self.label_2.setScaledContents(False) self.label_2.setWordWrap(False) self.label_2.setOpenExternalLinks(False) self.label_2.setObjectName("label_2") self.lineEdit_2 = QtWidgets.QLineEdit(self.tab) self.lineEdit_2.setGeometry(QtCore.QRect(310, 200, 171, 25)) self.lineEdit_2.setObjectName("lineEdit_2") self.label_3 = QtWidgets.QLabel(self.tab) self.label_3.setGeometry(QtCore.QRect(160, 200, 151, 21)) font = QtGui.QFont() font.setPointSize(13) font.setItalic(True) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.pushButton_4 = QtWidgets.QPushButton(self.tab) self.pushButton_4.setGeometry(QtCore.QRect(10, 330, 91, 31)) self.pushButton_4.setObjectName("pushButton_4") self.lineEdit = QtWidgets.QLineEdit(self.tab) self.lineEdit.setGeometry(QtCore.QRect(310, 160, 171, 25)) self.lineEdit.setObjectName("lineEdit") self.tabWidget.addTab(self.tab, "") self.tab_2 = QtWidgets.QWidget() self.tab_2.setObjectName("tab_2") self.label_4 = QtWidgets.QLabel(self.tab_2) self.label_4.setEnabled(True) self.label_4.setGeometry(QtCore.QRect(150, 10, 341, 41)) font = QtGui.QFont() font.setFamily("Century Schoolbook L") font.setPointSize(12) font.setBold(True) font.setItalic(True) font.setWeight(75) font.setKerning(True) self.label_4.setFont(font) self.label_4.setMouseTracking(False) self.label_4.setLayoutDirection(QtCore.Qt.LeftToRight) self.label_4.setAutoFillBackground(False) self.label_4.setTextFormat(QtCore.Qt.AutoText) self.label_4.setScaledContents(False) self.label_4.setWordWrap(False) self.label_4.setOpenExternalLinks(False) self.label_4.setObjectName("label_4") self.pushButton_5 = QtWidgets.QPushButton(self.tab_2) self.pushButton_5.setGeometry(QtCore.QRect(150, 80, 341, 41)) font = QtGui.QFont() font.setPointSize(14) font.setBold(False) font.setItalic(True) font.setWeight(50) self.pushButton_5.setFont(font) self.pushButton_5.setObjectName("pushButton_5") self.label_5 = QtWidgets.QLabel(self.tab_2) self.label_5.setGeometry(QtCore.QRect(150, 150, 151, 21)) font = QtGui.QFont() font.setPointSize(13) font.setItalic(True) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.lineEdit_3 = QtWidgets.QLineEdit(self.tab_2) self.lineEdit_3.setGeometry(QtCore.QRect(300, 150, 191, 25)) self.lineEdit_3.setObjectName("lineEdit_3") self.pushButton_6 = QtWidgets.QPushButton(self.tab_2) self.pushButton_6.setGeometry(QtCore.QRect(150, 200, 341, 41)) font = QtGui.QFont() font.setPointSize(15) font.setItalic(True) self.pushButton_6.setFont(font) self.pushButton_6.setObjectName("pushButton_6") self.pushButton_7 = QtWidgets.QPushButton(self.tab_2) self.pushButton_7.setGeometry(QtCore.QRect(540, 330, 91, 31)) self.pushButton_7.setObjectName("pushButton_7") self.pushButton_8 = QtWidgets.QPushButton(self.tab_2) self.pushButton_8.setGeometry(QtCore.QRect(10, 330, 91, 31)) self.pushButton_8.setObjectName("pushButton_8") self.textBrowser = QtWidgets.QTextBrowser(self.tab_2) self.textBrowser.setGeometry(QtCore.QRect(150, 260, 341, 61)) self.textBrowser.setObjectName("textBrowser") self.tabWidget.addTab(self.tab_2, "") self.image_file = ("0", "0") self.retranslateUi(Dialog) self.tabWidget.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButton.setText(_translate("Dialog", "Select the image")) self.pushButton_3.setText(_translate("Dialog", "Exit")) self.label.setText(_translate("Dialog", "Enter the text :")) self.pushButton_2.setText(_translate("Dialog", "Embed text in picture")) self.label_2.setText( _translate("Dialog", " Embedding encrypted text in the image")) self.label_3.setText(_translate("Dialog", "Enter password :"******"Dialog", "Main menu")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Dialog", "Embed text")) self.label_4.setText( _translate("Dialog", "Extract the encrypted text from the image")) self.pushButton_5.setText(_translate("Dialog", "Select the image")) self.label_5.setText(_translate("Dialog", "Enter password :"******"Dialog", "Extract text")) self.pushButton_7.setText(_translate("Dialog", "Exit")) self.pushButton_8.setText(_translate("Dialog", "Main menu")) self.textBrowser.setHtml( _translate( "Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans\'; font-size:10pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Encrypted and embedded text will appear here when extracted.</p></body></html>" )) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Dialog", "Extract text")) self.pushButton_3.clicked.connect(self.exit) self.pushButton_7.clicked.connect(self.exit) self.pushButton_4.clicked.connect(self.main) self.pushButton_8.clicked.connect(self.main) self.pushButton.clicked.connect(self.image) self.pushButton_2.clicked.connect(self.image_run) self.pushButton_5.clicked.connect(self.image) self.pushButton_6.clicked.connect(self.run_st) 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 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") def image(self): self.image_file = QFileDialog.getOpenFileName(os.getenv("Desktop")) try: Image.open(self.image_file[0]) except: self.pushButton_2.setText("Incorrect file type") def main(self): self.mainwin = QMainWindow() self.ui = main.Ui_Dialog(self.mainwin) self.ui.setupUi(self.mainwin) self.mainwin.setWindowTitle(" DEncrypt") self.mainwin.setFixedSize(666, 421) self.mainwin.move(300, 100) self.mainwin.show() self.a.hide() def exit(self): quit()
ip1 = socket.gethostbyname(hname) print('host name is:' + ip1) # calling run function x = ipaddress.ip_address(ip1) if (check(ip1) == 1 and x.version == 4): print("it is ipv4 address") else: print("please enter a valid ip address") crypto_steganography = CryptoSteganography('My secret password key') input_image = input("Enter image path: ") # Save the encrypted file inside the image crypto_steganography.hide(input_image, 'encrypted.png', ip1) img = Image.open("encrypted.png") img.save("encrypted.png") #filename = input("File to encrypt: ") filename = "encrypted.png" password = input("Password: ") encrypt(getKey(password), 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(password, public_key)
print( "Welcome to the program where we will encrpypt your passowrd in image for you." ) print() print("Press any key to continue...") input() print() print() masterKey = input( "Enter a key that you want to use throughout your lifetime: ") imageName = input("Enter the image name you want to put password to: ") outputName = input("Enter the name for your output image: ") print() imageName += ".jpg" outputName += ".png" from cryptosteganography import CryptoSteganography crypto_steganography = CryptoSteganography(masterKey) # Save the encrypted file inside the image passcode = input("Enter your secret passcode: ") crypto_steganography.hide(imageName, outputName, passcode) print("Successfully Encrypted...")
#Store a message string inside an image using python lib "cryptosteganography " #cryptosteganography --- A python steganography module to store messages or files protected with AES-256 encryption inside an image. from cryptosteganography import CryptoSteganography crypto_steganography = CryptoSteganography('thIsisThEseCRetKEy') #set a key # Save the encrypted file inside the image crypto_steganography.hide('puppy.jpg', 'puppywithsecret.png', 'Hello! This is a gsd puppy.') #secret message secret = crypto_steganography.retrieve( 'puppywithsecret.png') # read the .png and retrieve the message print(secret) #print the secret message after reading #cons -- output file size is considerably high compared to the original file
from cryptosteganography import CryptoSteganography message = None with open('filename_pi.obj.enc', "rb") as f: message = f.read() crypto_steganography = CryptoSteganography('My secret password key') crypto_steganography.hide('pip.jpg', 'output_image_file.png', message) crypto_steganography = CryptoSteganography('My secret password key') decrypted_bin = crypto_steganography.retrieve('output_image_file.png') # Save the data to a new file with open('decrypted_sample.mp3', 'wb') as f: f.write(secret_bin)