Esempio n. 1
0
    def extractMessageFromImage(self):
        #Create a NewSteg object
        steg = NewSteganography(self.currentPath)

        #Make sure it is set to the proper orientation
        steg.setProperOrientation()

        #Get the message from the image
        message = steg.extractMessageFromMedium()

        #Disable the extract button
        self.btnExtract.setEnabled(False)


        #Display the message based on the type
        if message.messageType == "GrayImage" :
            pass
            image = message.getDecodedGrayImage()
            self.displayExtractedGrayImage(image)

        elif message.messageType == "ColorImage" :
            image = message.getDecodedColorImage()
            self.displayExtractedColorImage(image)

        else :
            text = message.getDecodedText()
            self.displayExtractedText(text)
Esempio n. 2
0
    def confirmWipe(self):
        msgBox = QMessageBox()
        msgBox.setText('Confirm Wipe')
        msgBox.setInformativeText('Are you sure you want to wipe the current medium?')
        msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        msgBox.setDefaultButton(QMessageBox.No)
        ret = msgBox.exec_()

        # If the user selects yes
        if(ret == QMessageBox.Yes):
            n = NewSteganography(imagePath = self.imagePath, direction = self.imageDirection)

            # Call the wipe medium function, repopulate the origin fileTreeWidget
            n.wipeMedium()
            self.fileTreeWidget.clear()
            self.examineImages()

            # Clear the two graphics views in the stackedWidget
            self.txtMessage.clear()
            tempScene = QGraphicsScene()
            self.viewMessage.setScene(tempScene)

            self.btnWipeMedium.setDisabled(True)
            self.btnExtract.setDisabled(True)
            self.viewMessage.setHidden(True)
            self.txtMessage.setHidden(True)
            self.lblTextMessage.setText('Text')
            self.lblImageMessage.setText('Text')
            self.lblTextMessage.setDisabled(True)
            self.lblImageMessage.setDisabled(True)
Esempio n. 3
0
    def wipeMediumClicked(self):

        #Get the currently selected picture
        selected_item = self.fileTreeWidget.currentItem().text(0)

        #Construct the file path based on selected item
        path = self.directory + "/" + selected_item

        #Creat and display warning box
        msgBox = QMessageBox()
        msgBox.setWindowTitle("Confirmation Window")
        msgBox.setText("Are you sure you want to wipe medium?")

        msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        msgBox.setDefaultButton(QMessageBox.No)

        ret = msgBox.exec_()

        #If Yes was clicked
        if(ret == 16384):

            #Wipe the medium and adjust the file tree accordingly
            steg = NewSteganography(imagePath=path)
            child = self.fileTreeWidget.currentItem()
            child.takeChild(0)
            child.setForeground(0,QtGui.QBrush(Qt.blue))
            self.hidden_message_dict[child.text(0)] = None
            steg.wipeMedium()
            self.treeItemClicked()
    def extract(self):
        """
        extracts the message in the medium and places it in the graphics view or line edit based on what type the message is
        :return:
        """
        parentcheck = str(self.fileTreeWidget.currentItem().parent())
        if parentcheck == 'None':
            current = self.fileTreeWidget.currentItem()
        else:
            current = self.fileTreeWidget.currentItem().parent()
        path = self.fpdict[current]
        direction = self.childdict[current][1]
        medium = NewSteganography(path, direction)
        ex_message = medium.extractMessageFromMedium()
        ex_messagetype = ex_message.messageType

        """Options for message extraction put back"""

        if ex_messagetype == 'Text':
            dcode = ex_message.findmessage()                      #finds the message in the xml file
            msg = base64.b64decode(bytes(dcode, "UTF-8"))   #decodes the base64 message
            msg = str(msg, "UTF-8")
            self.txtMessage.setPlainText(msg)
            self.btnExtract.setEnabled(False)
        elif ex_messagetype == 'ColorImage':
            ex_message.saveToTarget('help.png')
            self.displayimageinmessage('help.png')
            self.btnExtract.setEnabled(False)
        elif ex_messagetype == 'GrayImage':
            ex_message.saveToTarget('help.png')
            self.displayimageinmessage('help.png')
            self.btnExtract.setEnabled(False)
Esempio n. 5
0
	def extract(self):
		self.btnExtract.setEnabled(False)
		self.txtMessage.setPlainText("")
		self.scn.clear()
		self.viewMessage.update()
		if self.selectedfile in self.v:														### Instantiate a class based on the method
			class1 = NewSteganography(self.path+"/"+self.selectedfile,"vertical")			### in which the message has been embedded in
		else:																				### the medium
			class1 = NewSteganography(self.path+"/"+self.selectedfile,"horizontal")

		tup = class1.checkIfMessageExists()													### if the message exists then display the
		message = class1.extractMessageFromMedium()											### message on the stack widget using the
		self.viewMessage.setEnabled(True)													### appropriate widget
		self.lblImageMessage.setEnabled(True)
		if tup[1] == "Text":
			self.stackMessage.setCurrentIndex(1)											### Also update the message label below the
			self.lblImageMessage.setText("Text")											### stacked widget
			message.saveToTarget("save.txt")
			filein = open("save.txt")
			data = filein.read()
			self.txtMessage.setPlainText(data)
		elif tup[1] == 'ColorImage' or tup[1] == 'GrayImage':
			self.stackMessage.setCurrentIndex(0)
			self.lblImageMessage.setText("Image")
			message.saveToTarget("save.png")
			self.viewMessage.setScene(self.scn)
			pixmap = QtGui.QPixmap("save.png")
			PixItem = self.scn.addPixmap(pixmap)

			self.viewMessage.fitInView(PixItem)
			self.viewMessage.show()
Esempio n. 6
0
    def getPictures(self,path):
        fileList = glob.glob(path+"/*.png")
        #print (fileList[0])

        for file in fileList:
            #print (file)
            file_name = file.split("/")[-1]
            #print (file_name)
            folder_name = file.split("/")[:-1]
            #print (folder_name)
            #folder_name =
            st = ""
            for s in folder_name:
                st += "/"
                st += s
            st = st.strip("/")
            st = "/"+st
            #print ("llll="+st)



            file_path = st + "/" +file_name
            self.first_path = st
            #print (file_path)
            medium = NewSteganography(file_path,"horizontal")
            o = medium.checkIfMessageExists()
            medium2 = NewSteganography(file_path,"vertical")
            o2 = medium2.checkIfMessageExists()
            #print (o)
            if o[0] == False and o2[0] == False:
                item = QTreeWidgetItem()

                item.setText(0,file_name)

                self.fileTreeWidget.addTopLevelItem(item)
                item.setForeground(0,QBrush(QColor(0,0,255)))

            elif o[0] == True:
                #print (o)
                item = QTreeWidgetItem()

                item.setText(0,file_name)
                self.fileTreeWidget.addTopLevelItem(item)
                item.setForeground(0,QBrush(QColor(255,0,0)))
                child = QTreeWidgetItem()
                child.setText(0,o[1])
                child.setForeground(0,QBrush(QColor(0,255,0)))
                item.addChild(child)
            else:
                item = QTreeWidgetItem()

                item.setText(0,file_name)
                self.fileTreeWidget.addTopLevelItem(item)
                item.setForeground(0,QBrush(QColor(255,0,0)))
                #item.QFont.setBold(True)
                child = QTreeWidgetItem()
                child.setText(0,o2[1])
                child.setForeground(0,QBrush(QColor(0,255,0)))
                item.addChild(child)
Esempio n. 7
0
    def wipeMed(self):  #the function that will wipe the medium
        #now, we will pop up a QMessageBox dialog asking the user to confirm their action.
        msgBox = QMessageBox()
        msgBox.setText(
            'Wiping the medium will remove all the contents from the medium.')
        msgBox.setInformativeText('Are you sure you want to proceed?')
        msgBox.setStandardButtons(
            QMessageBox.Yes
            | QMessageBox.No)  #yes or no option provided to the user
        ret = msgBox.exec_()  #to see what the user enters
        #print(type(ret))

        if (ret == 65536):  #i.e, the user selects the No option
            #just go back and return from the function
            return

        else:  #i.e, the user selects the Yes option

            #clear the message display unit for both image and text, whichever is applicable
            scene = QtGui.QGraphicsScene()
            scene.clear()
            self.viewMessage.setScene(scene)
            self.txtMessage.clear()

            self.btnWipeMedium.setEnabled(
                False)  #disable the wipe medium button

            #create a new NewSteg obj with any direction of rasterization, it does not matter since wiping the medium will essentially work for all the pixels. Thus for our purposes, we will use 'horizontal' as direction of rasterization. 'vertical' would also work just fine.
            self.grpMessage.setDisabled(
                True)  #diaable the stacked widget to display message

            curr = self.fileTreeWidget.currentItem()
            filename = curr.text(0)
            curr.takeChild(0)
            curr.setForeground(0, QtGui.QBrush(Qt.blue))
            for i in range(0, len(self.imgType)):
                if (filename == self.imgType[i][0]):
                    #print(self.imgType[i])
                    self.imgType[i] = (filename, (False, None))
                    #print(self.imgType[i])
                    break

            path = self.directorySelected + '/' + self.fileTreeWidget.currentItem(
            ).text(0)  #get the current image file
            stegobj = NewSteganography(
                path, 'horizontal'
            )  #create a NewSteg obj with horizontal rasterization
            stegobj.wipeMedium()  #call the function to wipe the medium
            '''
 def additem(self, path, item):
     self.fileTreeWidget.addTopLevelItem(item)
     horizontalread = NewSteganography(path, 'horizontal')
     verticalread = NewSteganography(path, 'vertical')
     ah,bh = horizontalread.checkIfMessageExists()
     av,bv = verticalread.checkIfMessageExists()
     if ah == True:
         item.setForeground(0,QtGui.QBrush(QtGui.QColor("#FF0000")))
         item.addChild(QTreeWidgetItem([bh]))
         self.childdict[item] = [bh, 'horizontal']
     elif av == True:
         item.setForeground(0,QtGui.QBrush(QtGui.QColor("#FF0000")))
         item.addChild(QTreeWidgetItem([bv]))
         self.childdict[item] = [bv, 'vertical']
     else:
         item.setForeground(0,QtGui.QBrush(QtGui.QColor("#0000FF")))
Esempio n. 9
0
    def wipe(self):
        rest = QtGui.QMessageBox.question(self, 'title', 'message',
                                          QtGui.QMessageBox.Yes,
                                          QtGui.QMessageBox.No)
        if rest == QtGui.QMessageBox.Yes:
            self.mode(False)
            item = self.fileTreeWidget.currentItem()
            subitem = item.child(0)
            dir = subitem.text(1)
            stegan = NewSteganography(self.imagepath, direction=dir)
            stegan.wipeMedium()
            item.removeChild(subitem)

            item.setForeground(0, QBrush(QColor(0, 0, 255)))
            foont = QtGui.QFont()
            foont.setBold(False)
            item.setFont(0, foont)
Esempio n. 10
0
    def extracting(self):
        # Pull values from the saved data
        path, direction, messageType = self.data
        self.btnExtract.setDisabled(True)

        # Check for message type
        if(messageType == 'Text'):
            # Change the current index
            self.stackMessage.setCurrentIndex(1)
            
            # Extract the message from the medium, and decode the base64 encoding
            n = NewSteganography(imagePath = path, direction = direction)

            message = n.extractMessageFromMedium()
            temporary = message.getXmlString()
            _, _, message, _ = message.xmlParse(temporary)

            textMessage = base64.b64decode(bytes(message, "UTF-8")).decode("ascii")

            # Clear the current text, then insert the text message
            self.txtMessage.clear()
            self.txtMessage.insertPlainText(textMessage)

        elif(messageType in ['GrayImage', 'ColorImage']):
            # Change the current index
            self.stackMessage.setCurrentIndex(0)

            # Create a new scene
            newScene = QGraphicsScene()
            n = NewSteganography(imagePath = path, direction = direction)

            # Extract the message
            messageToDisplay = n.extractMessageFromMedium()

            # Save the message to a temp file
            messageToDisplay.saveToTarget('.temp123.png')
            pixels = newScene.addPixmap(QPixmap('.temp123.png'))

            # Paint the extracted imaged
            self.viewMessage.setScene(newScene)
            self.viewMessage.fitInView(pixels, Qt.KeepAspectRatio)
            os.remove('.temp123.png')

            # Clear the text graphics view
            self.txtMessage.clear()
Esempio n. 11
0
    def wipeMed(self):#the function that will wipe the medium
        #now, we will pop up a QMessageBox dialog asking the user to confirm their action. 
        msgBox = QMessageBox()
        msgBox.setText('Wiping the medium will remove all the contents from the medium.')
        msgBox.setInformativeText('Are you sure you want to proceed?')
        msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) #yes or no option provided to the user
        ret = msgBox.exec_() #to see what the user enters
        #print(type(ret))

        if (ret == 65536): #i.e, the user selects the No option
            #just go back and return from the function
            return

        else: #i.e, the user selects the Yes option

            #clear the message display unit for both image and text, whichever is applicable
            scene = QtGui.QGraphicsScene()
            scene.clear()
            self.viewMessage.setScene(scene)
            self.txtMessage.clear()


            self.btnWipeMedium.setEnabled(False) #disable the wipe medium button

            #create a new NewSteg obj with any direction of rasterization, it does not matter since wiping the medium will essentially work for all the pixels. Thus for our purposes, we will use 'horizontal' as direction of rasterization. 'vertical' would also work just fine.
            self.grpMessage.setDisabled(True) #diaable the stacked widget to display message

            curr = self.fileTreeWidget.currentItem() #get the current tree widget, ie the current filename
            filename = curr.text(0) #get the text filename
            curr.takeChild(0) #remove the child
            curr.setForeground(0, QtGui.QBrush(Qt.blue)) #make color of filename in tree widget to appear to blue
            for i in range(0, len(self.imgType)): #now change the imgType list for the particulae filename, ie message type is none
                if (filename == self.imgType[i][0]):
                    #print(self.imgType[i])
                    self.imgType[i] = (filename, (False, None))
                    #print(self.imgType[i])
                    break #break out of loop to save time
            

            path = self.directorySelected + '/' + self.fileTreeWidget.currentItem().text(0) #get the current image file
            stegobj = NewSteganography(path, 'horizontal') #create a NewSteg obj with horizontal rasterization
            stegobj.wipeMedium() #call the function to wipe the medium
            '''
 def imgToMsgType(self): #the function that maps each image to the kind of message, if applicable
     path = self.directorySelected + '/' #the target image path woth the directory path that will be appended to each image file
     for i in self.imgFiles: #for all the image files 
         #for each image, since we don't know the kind of rasterization, we will first try with horizontal, then vertical, otherwise if both return false, we will return false
         imagePath = path + i #the image path
         #print(imagePath)
         hor_res = tuple #to store the result of horizontal rasterization
         ver_res = tuple #to store the result of horizontal rasterization
         newstegobj = NewSteganography(imagePath, 'horizontal')
         hor_res = newstegobj.checkIfMessageExists()
         if (hor_res[0] == True): #if horizontally rasterized and message exists
             tup = tuple
             tup = (i, hor_res) #make the tuple that maps the image name to the type of embedded message
             self.imgType.append(tup) #append to the list that stores for all the image files information about type of message embedded
             continue #go on to the next image file
         else: #either not horizontally rasterized or no message at all, we will now check for vertical rasterization
             newstegobj = NewSteganography(imagePath, 'vertical')
             ver_res = newstegobj.checkIfMessageExists()
             if (ver_res[0] == True): #if vertically rasterized and message exists
                 tup = tuple
                 tup = (i, ver_res) #make the tuple that maps the image name to the type of embedded message
                 self.imgType.append(tup) #append to the list that stores for all the image files information about type of message embedded
             else: #neither horizontal nor vertical => no message embedded
                 tup = tuple
                 tup = (i, ver_res) #make the tuple that maps the image name to the type of embedded message
                 self.imgType.append(tup) #append to the list that stores for all the image files information about type of message embedded
             continue #go on to the next image file
Esempio n. 13
0
    def setupFileTree(self):
        #Keep a dictionary to track which files had messages in them
        hidden_message_types = dict()
        file_paths = glob(self.directory + "/*.png")

        files = [os.path.basename(path) for path in file_paths]

        if(files == []):
            return

        #Go through each of the files and check if they have a message in them
        for file in files :
            try:
                steg = NewSteganography(self.directory + "/" + file)

            except TypeError:
                continue

            #Add each element into the treeview appropriately
            child = QTreeWidgetItem()
            child.setText(0,file)

            exists, type = steg.checkIfMessageExists()
            hidden_message_types[file] = type

            #If it has a message inside, color and extend appropriately
            if(exists) :
                child.setForeground(0,QtGui.QBrush(Qt.red))
                second_child = QTreeWidgetItem()
                second_child.setText(0,type)
                second_child.setForeground(0,QtGui.QBrush(Qt.green))
                child.addChild(second_child)
            else:
                child.setForeground(0,QtGui.QBrush(Qt.blue))

            self.fileTreeWidget.addTopLevelItem(child)

        #Expand all the list items and update the dictionary
        self.fileTreeWidget.expandAll()
        self.hidden_message_dict = hidden_message_types
Esempio n. 14
0
    def getPictures(self, path):
        fileList = glob.glob(path + "/*.png")
        #print (fileList[0])

        for file in fileList:
            #print (file)
            file_name = file.split("/")[-1]
            #print (file_name)
            folder_name = file.split("/")[:-1]
            #print (folder_name)
            #folder_name =
            st = ""
            for s in folder_name:
                st += "/"
                st += s
            st = st.strip("/")
            st = "/" + st
            #print ("llll="+st)

            file_path = st + "/" + file_name
            self.first_path = st
            #print (file_path)
            medium = NewSteganography(file_path, "horizontal")
            o = medium.checkIfMessageExists()
            medium2 = NewSteganography(file_path, "vertical")
            o2 = medium2.checkIfMessageExists()
            #print (o)
            if o[0] == False and o2[0] == False:
                item = QTreeWidgetItem()

                item.setText(0, file_name)

                self.fileTreeWidget.addTopLevelItem(item)
                item.setForeground(0, QBrush(QColor(0, 0, 255)))

            elif o[0] == True:
                #print (o)
                item = QTreeWidgetItem()

                item.setText(0, file_name)
                self.fileTreeWidget.addTopLevelItem(item)
                item.setForeground(0, QBrush(QColor(255, 0, 0)))
                child = QTreeWidgetItem()
                child.setText(0, o[1])
                child.setForeground(0, QBrush(QColor(0, 255, 0)))
                item.addChild(child)
            else:
                item = QTreeWidgetItem()

                item.setText(0, file_name)
                self.fileTreeWidget.addTopLevelItem(item)
                item.setForeground(0, QBrush(QColor(255, 0, 0)))
                #item.QFont.setBold(True)
                child = QTreeWidgetItem()
                child.setText(0, o2[1])
                child.setForeground(0, QBrush(QColor(0, 255, 0)))
                item.addChild(child)
 def wipe(self):
     """
     cleans the message from the medium and refreshes the item based on the new properties of the medium
     :return:
     """
     msgbox = QMessageBox()
     msgbox.setText("Are you sure you want to wipe the medium?")
     msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
     option = msgbox.exec_()
     if option == QMessageBox.No:
         pass
     elif option == QMessageBox.Yes:
         self.viewMessage.setHidden(True)
         self.txtMessage.setHidden(True)
         current = self.fileTreeWidget.currentItem()
         path = self.fpdict[current]
         direction = self.childdict[current][1]
         medium = NewSteganography(path, direction)
         medium.wipeMedium()
         scene = QGraphicsScene()
         self.viewMessage.setScene(scene)
         current.takeChild(0)
         self.fileTreeWidget.removeItemWidget(current, 0)
         self.additem(path, current)
Esempio n. 16
0
    def __init__(self, parent=None):
        super(SteganographyBrowser, self).__init__(parent)
        self.setupUi(self)


        self.path = QtGui.QFileDialog.getExistingDirectory()
        if not self.path:
            exit()
        # print(self.path)
        foldername = self.path.split('/')[-1]
        # print(foldername)
        self.fileTreeWidget.setHeaderLabel(foldername)
        filelist = glob.glob(self.path + '/*.png')
        # print(filelist)


        # treeWidget = self.fileTreeWidget
        # treeWidget.setColumnCount(1)
        items = []
        for files in filelist:
            # the try-except part prevent color image from adding into the widget
            try:
                stegan = NewSteganography(files)
                # print(files)
                exist, ttype = stegan.checkIfMessageExists()
                if exist is False:
                    stegan = NewSteganography(files, 'vertical')
                    exist, ttype = stegan.checkIfMessageExists()

                item = QTreeWidgetItem(self.fileTreeWidget)
                name = files.split('/')[-1]
                # name = re.findall(r'/.*/(.*?\.png)', files)
                # print(name)
                # print(files)
                item.setText(0, name)

                if exist is False:
                    item.setForeground(0, QBrush(QColor(0, 0, 255)))
                else:
                    item.setForeground(0, QBrush(QColor(255, 0, 0)))
                    foont = QtGui.QFont()
                    foont.setBold(True)
                    item.setFont(0, foont)

                    son = QTreeWidgetItem(item)
                    son.setText(0, ttype)
                    son.setForeground(0, QBrush(QColor(0, 255, 0)))
                items += [item]
            except:
                pass
        #
        self.fileTreeWidget.addTopLevelItems(items)
        self.mode(False)

        self.fileTreeWidget.itemClicked.connect(self.display)
Esempio n. 17
0
 def extractMessage(self): #the function to extract the message
     #print(self.stackMessage.currentIndex())
     #self.stackMessage.setCurrentIndex(1)
     #first of all, if it reaches this position then we know that the medium embeds a message, otherwise Extract Message button will be disabled. So, our first order of business will be figure out if the message embedded is Text or Image (Gray/Color), and then set the StackWidget frame to Text or Graphics accordingly
     self.grpMessage.setDisabled(False) #enable the stacked widget to display message
     typeOfMsg = self.fileTreeWidget.currentItem().child(0).text(0) #get the type of message corresponding to the medium
     if (typeOfMsg == 'ColorImage') or (typeOfMsg == 'GrayImage'):#if it is a form of image that is embedded
         self.stackMessage.setCurrentIndex(0)#then work in the graphics view
         #now that we have set to graphics view, we have to get the message out and display it on the frame
         #first of all, make a NewSteganography object with imagePath as the current image file that is chosen and a direction as horizontal. If horizontal produces a None message from extraction, then try vertical rasterization.
         path = self.directorySelected + '/' + self.fileTreeWidget.currentItem().text(0) #get the current image file
         stegobj = NewSteganography(path, 'horizontal') #create a NewSteg obj with horizontal rasterization
         msg = stegobj.extractMessageFromMedium()
         targetPath = 'putMsg.png' #the target path where the message will be stored, this will be deleted eventually
         if (msg is None): #basically horizontal rasterization did not work
             stegobj = NewSteganography(path, 'vertical') #create a NewSteg obj with vertical rasterization
             msg2 = stegobj.extractMessageFromMedium() #now this will have produced a message
             msg2.saveToTarget(targetPath) #put the message in the target path image file
         else: #horizontal rasterization worked
             msg.saveToTarget(targetPath) #put the message in the target path image file
         #now, its time to put the message in the Graphics View widget
         scene = QGraphicsScene()
         scene.addPixmap(QPixmap(targetPath))
         self.viewMessage.setScene(scene)
         self.viewMessage.fitInView(self.viewMessage.sceneRect(), QtCore.Qt.KeepAspectRatio) #put the image in the Graphics View widget and fit it to scale such that no scrolling is required
         os.remove(targetPath)#remove the message file created
     else: #if it is a text
         self.stackMessage.setCurrentIndex(1)#the work in the line edit 
         #first of all, make a NewSteganography object with imagePath as the current image file that is chosen and a direction as horizontal. If horizontal produces a None message from extraction, then try vertical rasterization.
         path = self.directorySelected + '/' + self.fileTreeWidget.currentItem().text(0) #get the current image file
         stegobj = NewSteganography(path, 'horizontal') #create a NewSteg obj with horizontal rasterization
         msg = stegobj.extractMessageFromMedium()
         targetPath = 'putMsg.txt' #the target path where the message will be stored, this will be deleted eventually
         if (msg is None): #basically horizontal rasterization did not work
             stegobj = NewSteganography(path, 'vertical') #create a NewSteg obj with vertical rasterization
             msg2 = stegobj.extractMessageFromMedium() #now this will have produced a message
             msg2.saveToTarget(targetPath) #put the message in the target path image file
         else: #horizontal rasterization worked
             msg.saveToTarget(targetPath) #put the message in the target path image file
         f = open(targetPath, 'r') #open the target file text file for reading from
         txt = f.read() #read all the contents of the file
         self.txtMessage.setPlainText(txt) #write the message contents to the text editor's contents
         os.remove(targetPath)#remove the message file created
     self.btnExtract.setEnabled(False) #disable the extract message button
Esempio n. 18
0
    def __init__(self, parent=None):
        super(SteganographyBrowser, self).__init__(parent)
        self.setupUi(self)

        self.path = QtGui.QFileDialog.getExistingDirectory()
        if not self.path:
            exit()
        foldername = self.path.split('/')[-1]
        self.fileTreeWidget.setHeaderLabel(foldername)
        filelist = glob.glob(self.path + '/*.png')

        items = []
        for files in filelist:
            # the try-except part prevent color image from adding into the widget
            try:
                stegan = NewSteganography(files)
                exist, ttype = stegan.checkIfMessageExists()
                direction = 'horizontal'
                if exist is False:
                    direction = 'vertical'
                    stegan = NewSteganography(files, 'vertical')
                    exist, ttype = stegan.checkIfMessageExists()

                item = QTreeWidgetItem(self.fileTreeWidget)
                name = files.split('/')[-1]
                item.setText(0, name)

                if exist is False:
                    item.setForeground(0, QBrush(QColor(0, 0, 255)))
                else:
                    item.setForeground(0, QBrush(QColor(255, 0, 0)))
                    foont = QtGui.QFont()
                    foont.setBold(True)
                    item.setFont(0, foont)

                    son = QTreeWidgetItem(item)
                    son.setText(0, ttype)
                    son.setText(1, direction)
                    son.setForeground(0, QBrush(QColor(0, 255, 0)))
                items += [item]
            except:
                pass
        self.fileTreeWidget.addTopLevelItems(items)
        self.mode(False)

        self.fileTreeWidget.itemClicked.connect(self.display)
        self.btnExtract.clicked.connect(self.extract)
        self.btnWipeMedium.clicked.connect(self.wipe)
Esempio n. 19
0
	def wipe(self):
		box = QMessageBox()																	### Creates a cautionary message box
		reply = box.question(None,"Caution","Wiped message cannot be recovered.Do you want to proceed?",QMessageBox.Ok | QMessageBox.Cancel)
		if reply == QMessageBox.Ok:															### If okay is pressed execute the below code
			if self.selectedfile in self.v:													
				class1 = NewSteganography(self.path+"/"+self.selectedfile,"vertical")
				class1.wipeMedium()															### if the item has vertically embedded
				self.v.remove(self.selectedfile)											### message then wipe the message
				self.btnExtract.setEnabled(False)											### and remove the item and its child from
				self.btnWipeMedium.setEnabled(False)										### tree widget
				item = QTreeWidgetItem([self.selectedfile])
				olditem = self.fileTreeWidget.selectedItems()[0]
				child = olditem.takeChildren()
				self.dict[self.selectedfile] = "0"
				self.fileTreeWidget.takeTopLevelItem(self.fileTreeWidget.indexOfTopLevelItem(olditem))
				item.setText(0,"{0}".format(olditem.text(0)))
				item.setForeground(0,QtGui.QBrush(Qt.blue))
				self.blueitems.append(item)
				self.fileTreeWidget.addTopLevelItem(item)
				self.fileTreeWidget.removeItemWidget(item,0)
			else:
				class1 = NewSteganography(self.path+"/"+self.selectedfile,"horizontal")
				class1.wipeMedium()															### if the item has horizontally embedded
				self.h.remove(self.selectedfile)											### message then wipe the message and
				self.btnExtract.setEnabled(False)											### remove the item and its child from the
				self.btnWipeMedium.setEnabled(False)										### tree widget
				item = QTreeWidgetItem([self.selectedfile])
				olditem = self.fileTreeWidget.selectedItems()[0]
				child = olditem.takeChildren()
				self.dict[self.selectedfile] = "0"
				self.fileTreeWidget.takeTopLevelItem(self.fileTreeWidget.indexOfTopLevelItem(olditem))
				item.setText(0,"{0}".format(olditem.text(0)))
				item.setForeground(0,QtGui.QBrush(Qt.blue))
				self.blueitems.append(item)
				self.fileTreeWidget.addTopLevelItem(item)
				self.fileTreeWidget.removeItemWidget(item,0)
			self.extract()
Esempio n. 20
0
 def extractMessage(self):  #the function to extract the message
     #print(self.stackMessage.currentIndex())
     #self.stackMessage.setCurrentIndex(1)
     #first of all, if it reaches this position then we know that the medium embeds a message, otherwise Extract Message button will be disabled. So, our first order of business will be figure out if the message embedded is Text or Image (Gray/Color), and then set the StackWidget frame to Text or Graphics accordingly
     self.grpMessage.setDisabled(
         False)  #enable the stacked widget to display message
     typeOfMsg = self.fileTreeWidget.currentItem().child(0).text(
         0)  #get the type of message corresponding to the medium
     if (typeOfMsg == 'ColorImage') or (
             typeOfMsg
             == 'GrayImage'):  #if it is a form of image that is embedded
         self.stackMessage.setCurrentIndex(
             0)  #then work in the graphics view
         #now that we have set to graphics view, we have to get the message out and display it on the frame
         #first of all, make a NewSteganography object with imagePath as the current image file that is chosen and a direction as horizontal. If horizontal produces a None message from extraction, then try vertical rasterization.
         path = self.directorySelected + '/' + self.fileTreeWidget.currentItem(
         ).text(0)  #get the current image file
         stegobj = NewSteganography(
             path, 'horizontal'
         )  #create a NewSteg obj with horizontal rasterization
         msg = stegobj.extractMessageFromMedium()
         targetPath = 'putMsg.png'  #the target path where the message will be stored, this will be deleted eventually
         if (msg is None):  #basically horizontal rasterization did not work
             stegobj = NewSteganography(
                 path, 'vertical'
             )  #create a NewSteg obj with vertical rasterization
             msg2 = stegobj.extractMessageFromMedium(
             )  #now this will have produced a message
             msg2.saveToTarget(
                 targetPath)  #put the message in the target path image file
         else:  #horizontal rasterization worked
             msg.saveToTarget(
                 targetPath)  #put the message in the target path image file
         #now, its time to put the message in the Graphics View widget
         scene = QGraphicsScene()
         scene.addPixmap(QPixmap(targetPath))
         self.viewMessage.setScene(scene)
         self.viewMessage.fitInView(
             self.viewMessage.sceneRect(), QtCore.Qt.KeepAspectRatio
         )  #put the image in the Graphics View widget and fit it to scale such that no scrolling is required
         os.remove(targetPath)  #remove the message file created
     else:  #if it is a text
         self.stackMessage.setCurrentIndex(1)  #the work in the line edit
         #first of all, make a NewSteganography object with imagePath as the current image file that is chosen and a direction as horizontal. If horizontal produces a None message from extraction, then try vertical rasterization.
         path = self.directorySelected + '/' + self.fileTreeWidget.currentItem(
         ).text(0)  #get the current image file
         stegobj = NewSteganography(
             path, 'horizontal'
         )  #create a NewSteg obj with horizontal rasterization
         msg = stegobj.extractMessageFromMedium()
         targetPath = 'putMsg.txt'  #the target path where the message will be stored, this will be deleted eventually
         if (msg is None):  #basically horizontal rasterization did not work
             stegobj = NewSteganography(
                 path, 'vertical'
             )  #create a NewSteg obj with vertical rasterization
             msg2 = stegobj.extractMessageFromMedium(
             )  #now this will have produced a message
             msg2.saveToTarget(
                 targetPath)  #put the message in the target path image file
         else:  #horizontal rasterization worked
             msg.saveToTarget(
                 targetPath)  #put the message in the target path image file
         f = open(targetPath,
                  'r')  #open the target file text file for reading from
         txt = f.read()  #read all the contents of the file
         self.txtMessage.setPlainText(
             txt)  #write the message contents to the text editor's contents
         os.remove(targetPath)  #remove the message file created
     self.btnExtract.setEnabled(False)  #disable the extract message button
Esempio n. 21
0
    def displayMedium(self):
        self.grpMedium.setEnabled(True)
        #self.grpMessage.setEnabled(False)
        self.btnWipeMedium.setEnabled(False)
        self.btnExtract.setEnabled(False)
        print ("displayMdium")

        it = self.fileTreeWidget.currentItem()
        self.item = it
        #self.it = it
        file_name = it.text(0)
        self.file_path = self.first_path+"/"+file_name
        print (file_name)
        scene = QGraphicsScene()
        self.viewMedium.setScene(scene)
        pix_map = QPixmap(self.file_path)
        pix_it = QGraphicsPixmapItem(pix_map)
        scene.addItem(pix_it)
        #scene.setSceneRect(0,0,250,250)
        self.viewMedium.fitInView(scene.sceneRect(),Qt.KeepAspectRatio)
        self.viewMedium.show()
        self.txtMessage.setPlainText("")

        sc = QGraphicsScene()
        self.viewMessage.setScene(sc)


        medium = NewSteganography(self.file_path,"horizontal")
        #self.medium = medium
        medium2 = NewSteganography(self.file_path,"vertical")
        #self.medium2 = medium2
        o = medium.checkIfMessageExists()
        o2 = medium2.checkIfMessageExists()
        print ("o"+str(o[0]))
        print ("o2[0]"+str(o2[0]))
        if o[0] == True or o2[0] == True:
            self.btnWipeMedium.setEnabled(True)
            self.btnExtract.setEnabled(True)
            self.grpMessage.setEnabled(True)
            if o[1] == "GrayImage" or o[1] == "ColorImage":
                print ("case1start")

                self.stackMessage.setCurrentWidget(self.pgImage)
                message = medium.extractMessageFromMedium()
                target = "extract.png"
                self.target = target
                self.type = "Image"
                message.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractImage(target))
                self.medium = medium
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print ("case1end")
                #self.btnWipeMedium.clicked.connect(lambda: self.wipe(self.file_path))
            elif o2[1] == "GrayImage" or o2[1] == "ColorImage":
                print ("case2start")
                #self.grpMessage.setEnabled(True)
                self.stackMessage.setCurrentWidget(self.pgImage)
                message2 = medium2.extractMessageFromMedium()
                target = "extract.png"
                self.target = target
                self.type = "Image"
                message2.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractImage(target))
                self.medium = medium2
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print ("case2end")
                #self.btnWipeMedium.clicked.connect(lambda: self.wipe(self.file_path))
            elif o[1] == "Text":
                print ("case3start")
                self.stackMessage.setCurrentWidget(self.pgText)
                message = medium.extractMessageFromMedium()
                target = "extract.txt"
                self.target = target
                self.type = "Text"
                message.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractText(target))
                self.medium = medium
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print ("case3end")
            else:
                print ("case4tart")
                self.stackMessage.setCurrentWidget(self.pgText)
                message2 = medium2.extractMessageFromMedium()
                target = "extract.txt"
                self.target = target
                self.type = "Text"
                message2.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractText(target))
                self.medium = medium2
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print ("case4end")

        else:
            print ("caseNonestart")
            self.btnWipeMedium.setEnabled(False)
            self.btnExtract.setEnabled(False)
            self.grpMessage.setEnabled(False)
            print ("caseNoneend")
Esempio n. 22
0
    def displayMedium(self):
        self.grpMedium.setEnabled(True)
        #self.grpMessage.setEnabled(False)
        self.btnWipeMedium.setEnabled(False)
        self.btnExtract.setEnabled(False)
        print("displayMdium")

        it = self.fileTreeWidget.currentItem()
        self.item = it
        #self.it = it
        file_name = it.text(0)
        self.file_path = self.first_path + "/" + file_name
        print(file_name)
        scene = QGraphicsScene()
        self.viewMedium.setScene(scene)
        pix_map = QPixmap(self.file_path)
        pix_it = QGraphicsPixmapItem(pix_map)
        scene.addItem(pix_it)
        #scene.setSceneRect(0,0,250,250)
        self.viewMedium.fitInView(scene.sceneRect(), Qt.KeepAspectRatio)
        self.viewMedium.show()
        self.txtMessage.setPlainText("")

        sc = QGraphicsScene()
        self.viewMessage.setScene(sc)

        medium = NewSteganography(self.file_path, "horizontal")
        #self.medium = medium
        medium2 = NewSteganography(self.file_path, "vertical")
        #self.medium2 = medium2
        o = medium.checkIfMessageExists()
        o2 = medium2.checkIfMessageExists()
        print("o" + str(o[0]))
        print("o2[0]" + str(o2[0]))
        if o[0] == True or o2[0] == True:
            self.btnWipeMedium.setEnabled(True)
            self.btnExtract.setEnabled(True)
            self.grpMessage.setEnabled(True)
            if o[1] == "GrayImage" or o[1] == "ColorImage":
                print("case1start")

                self.stackMessage.setCurrentWidget(self.pgImage)
                message = medium.extractMessageFromMedium()
                target = "extract.png"
                self.target = target
                self.type = "Image"
                message.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractImage(target))
                self.medium = medium
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print("case1end")
                #self.btnWipeMedium.clicked.connect(lambda: self.wipe(self.file_path))
            elif o2[1] == "GrayImage" or o2[1] == "ColorImage":
                print("case2start")
                #self.grpMessage.setEnabled(True)
                self.stackMessage.setCurrentWidget(self.pgImage)
                message2 = medium2.extractMessageFromMedium()
                target = "extract.png"
                self.target = target
                self.type = "Image"
                message2.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractImage(target))
                self.medium = medium2
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print("case2end")
                #self.btnWipeMedium.clicked.connect(lambda: self.wipe(self.file_path))
            elif o[1] == "Text":
                print("case3start")
                self.stackMessage.setCurrentWidget(self.pgText)
                message = medium.extractMessageFromMedium()
                target = "extract.txt"
                self.target = target
                self.type = "Text"
                message.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractText(target))
                self.medium = medium
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print("case3end")
            else:
                print("case4tart")
                self.stackMessage.setCurrentWidget(self.pgText)
                message2 = medium2.extractMessageFromMedium()
                target = "extract.txt"
                self.target = target
                self.type = "Text"
                message2.saveToTarget(target)
                #self.btnExtract.clicked.connect(lambda: self.extractText(target))
                self.medium = medium2
                #self.btnWipeMedium.clicked.connect(self.boxQuestion)
                print("case4end")

        else:
            print("caseNonestart")
            self.btnWipeMedium.setEnabled(False)
            self.btnExtract.setEnabled(False)
            self.grpMessage.setEnabled(False)
            print("caseNoneend")
Esempio n. 23
0
	def __init__(self,parent = None):
		super(SteganographyGUI,self).__init__(parent)
		self.setupUi(self)

		filepath = QFileDialog.getExistingDirectory(self,"open folder only",Options = QFileDialog.ShowDirsOnly)
		if not filepath:
			sys.exit(1)

		self.selectedfile = ""
		self.path = filepath
		newfilepath = str(filepath).split("/")
		filesd = newfilepath[-1]
		self.fileTreeWidget.setHeaderLabel(newfilepath[-1])									### Labelling the treewidget with 
		self.scn = QGraphicsScene()															### the file path
		self.btnExtract.clicked.connect(self.extract)
		self.btnExtract.setEnabled(False)
		self.btnWipeMedium.setEnabled(False)
		self.viewMedium.setEnabled(False)
		self.viewMessage.setEnabled(False)
		self.lblImageMessage.setEnabled(False)

		blue = []
		vertical = []
		horizontal = []
		files = glob.glob(str(filepath)+"/*.png")
		for f in files:																		### Sorting the files as per image
			f = f.split("/")[-1]															### content and the method in which
			y = re.findall('(v|h)',f)														### the message is saved
			if not y:																		### E.g horizontal or vertical
				blue.append(f)
			elif y[0] == 'v':
				im = Image.open(str(filepath)+"/"+f)
				if im.mode == 'L':
					vertical.append(f)
				else:
					blue.append(f)
			elif y[0] == 'h':
				im = Image.open(str(filepath)+"/"+f)
				if im.mode == 'L':
					horizontal.append(f)
				else:
					blue.append(f)

		self.b = blue
		self.v = copy.deepcopy(vertical)
		self.h = copy.deepcopy(horizontal)
		self.dict = {}																		### Creating a dictionary that holds
																							### all the message images and the type
		self.blueitems = []																	### messages they contain if any
		for f in range(len(blue)):
			item = QTreeWidgetItem()
			item.setText(0,"{0}".format(blue[f]))											### Create item widgets for files with
			item.setForeground(0,QtGui.QBrush(Qt.blue))										### no content in them
			self.blueitems.append(item)
			self.dict[blue[f]] = "0"

		x = f + 1
		self.verticalitems = []
		for f in range(len(vertical)):														### Create a list of item widgets from
			item = QTreeWidgetItem(["{0}".format(vertical[f])])								### message mediums that have vertical
			class1 = NewSteganography(str(filepath+"/" + vertical[f]),'vertical')			### messages embedded in them.
			tup = class1.checkIfMessageExists()
			if tup[0]:
				item.addChild(QTreeWidgetItem([tup[1]]))
				self.dict[vertical[f]] = tup[1]
				item.setForeground(0,QtGui.QBrush(Qt.red))
				self.verticalitems.append(item)
			else:
				self.dict[vertical[f]] = tup[1]
				item.setForeground(0,QtGui.QBrush(Qt.blue))
				self.blueitems.append(item)
				self.v.remove(vertical[f])

		for f in range(len(self.verticalitems)):
			self.fileTreeWidget.addTopLevelItem(self.verticalitems[f])

		x += f + 1
		self.horizontalitems = []
		for f in range(len(horizontal)):													### Create a list of item widgets from
			item = QTreeWidgetItem(["{0}".format(horizontal[f])])							### message mediums that have horizontal
			class1 = NewSteganography(str(filepath+"/" + horizontal[f]),'horizontal')		### messages embedded in them.
			tup = class1.checkIfMessageExists()
			if tup[0]:
				item.addChild(QTreeWidgetItem([tup[1]]))
				self.dict[horizontal[f]] = tup[1]
				item.setForeground(0,QtGui.QBrush(Qt.red))
				self.horizontalitems.append(item)

			else:
				self.dict[horizontal[f]] = tup[1]
				item.setForeground(0,QtGui.QBrush(Qt.blue))
				self.blueitems.append(item)
				self.h.remove(horizontal[f])

		for f in range(len(self.horizontalitems)):
			self.fileTreeWidget.addTopLevelItem(self.horizontalitems[f])

		for f in range(len(self.blueitems)):
			self.fileTreeWidget.insertTopLevelItem(f,self.blueitems[f])
		
		self.fileTreeWidget.itemSelectionChanged.connect(self.blueClick)
		self.btnExtract.clicked.connect(self.extract)
		self.btnWipeMedium.clicked.connect(self.wipe)