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
Example #2
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)
Example #3
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)
Example #4
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)
 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
Example #6
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
            '''
Example #7
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)
Example #8
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")