Beispiel #1
0
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.")
Beispiel #2
0
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)
Beispiel #3
0
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
Beispiel #5
0
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_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 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
Beispiel #8
0
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)
Beispiel #10
0
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)
Beispiel #11
0
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)
Beispiel #12
0
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",
    )
Beispiel #13
0
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})
Beispiel #14
0
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]})
Beispiel #17
0
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()
Beispiel #18
0
def extract_file(filename, password='******'):  # Elm34lp9mvm43l23n4lkmmlkqwe
    crypto_steganography = CryptoSteganography(password)
    decrypted_bin = crypto_steganography.retrieve(filename)
    with open('test.txt.aes', 'wb') as f:
        f.write(decrypted_bin)
Beispiel #19
0
#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)
Beispiel #21
0
from cryptosteganography import CryptoSteganography
masterKey = input()
crypto_steganography = CryptoSteganography(masterKey)
secret = crypto_steganography.retrieve("Ren.png")
print(secret)
input()
def test_retrieve_from_raw_image(key: str) -> None:

    crypto_steganography = CryptoSteganography(key)
    secret = crypto_steganography.retrieve(INPUT_IMAGE)

    assert secret is None
def test_save_invalid(key: str) -> None:

    crypto_steganography = CryptoSteganography(key)
    secret = crypto_steganography.retrieve(INPUT_IMAGE)

    assert secret is None