Esempio n. 1
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()
    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. 3
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. 4
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()
 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. 6
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. 7
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")