0

I have encoded some user input successfully. But I cannot decode it.

Here is my code:

from PyQt4 import QtGui, QtCore
import sys, os
from PyQt4.Qt import SIGNAL, SLOT, QMainWindow, qApp, QUrl, QImage,\
QStringListModel
import hashlib
import base64

class Dialog_01(QtGui.QMainWindow):
    def __init__(self):
        super(QtGui.QMainWindow,self).__init__()
        myQWidget = QtGui.QWidget()
        myBoxLayout = QtGui.QVBoxLayout()
        myQWidget.setLayout(myBoxLayout)
        self.setCentralWidget(myQWidget)

        self.line = QtGui.QLineEdit(self)
        self.line.setObjectName("host")
        savebutton = QtGui.QPushButton("Print")
        savebutton.setMinimumSize(35,30)
        savebutton.clicked.connect(self.printtext)        
        myBoxLayout.addWidget(savebutton)

    def printtext(self):
       shost = self.line.text()
       #shost = "Hello"
       #print(self.ComboBox.currentText())
       self.md = hashlib.md5()
       self.md.update(shost.encode())
       str1 = (self.md.hexdigest())
       print(str1)

       str2 = codecs.decode(s, '5d41402abc4b2a76b9719d911017c592')
       print(str2)


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    dialog_1 = Dialog_01()
    dialog_1.show()
    dialog_1.resize(480,320)
    sys.exit(app.exec_())

What I want here is to decode the encrypted string (str1).

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Dhivya Prabha
  • 77
  • 2
  • 8
  • You're MD5 hashing the original string, which is a **one-way** hash. It can't be decoded. If you want to do string matching or some other operation on the hashed string, you'll have to hash another string the same way and check if they match. – economy Apr 03 '15 at 18:18

1 Answers1

0

You cannot use secure hash functions to encrypt/decrypt strings.

In fact, hash algorithms are specifically designed so that their output cannot be decrypted - that's what makes them secure! Hashes are usually used to check the authenticity of transferred data. If the hash of the current data matches the hash of the original data, you can be confident that they are the same data.

There is no built-in encryption/decryption in either Python or Qt, so if you want that, you will need to use a third-party library, such as simple-crypt or pycrypto.

On the other hand, if all you want is non-secure obfuscation, take a look at some of the suggestions in this SO question:

Community
  • 1
  • 1
ekhumoro
  • 115,249
  • 20
  • 229
  • 336