示例#1
0
    def __init__(self, parent=None):

        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        # self.ui.setupUi(self)   
        # super(Window, self).__init__(parent)
        self.ui.setupUi(self)

        self.connect(self.ui.addFileButton, QtCore.SIGNAL('pressed()'),self.openFile)
        self.connect(self.ui.composeButton, QtCore.SIGNAL('pressed()'),self.compose)
示例#2
0
class MainForm(QtGui.QMainWindow):
    def __init__(self, parent=None):

        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        # self.ui.setupUi(self)   
        # super(Window, self).__init__(parent)
        self.ui.setupUi(self)

        self.connect(self.ui.addFileButton, QtCore.SIGNAL('pressed()'),self.openFile)
        self.connect(self.ui.composeButton, QtCore.SIGNAL('pressed()'),self.compose)

    def compose(self):
        secretParts = []

        files = self.ui.listOfFiles.findItems("",QtCore.Qt.MatchContains)

        secretPartFile = open(files[0].text(),"rb")

        result = int(secretPartFile.read(),2)
        secretPartFile.close()
        i = 1
        while i<files.__len__():
            secretPartFile = open(files[i].text(),"rb")
            result = result.__xor__(int(secretPartFile.read(),2))
            secretPartFile.close()
            i = i+1

        result = bin(result)[2:]
        reverseResult = ""
        while result.__len__() > 0:
            reverseResult = reverseResult + result[-128:]
            result = result[:-128]
            print "+++"+reverseResult[-128:]
        reverseResult = reverseResult + result
        secretRevealed = ""
        
        while reverseResult.__len__() >= 128:
            secretBinPart = reverseResult[:8]
            reverseResult = reverseResult[8:]
            secretRevealed =  secretRevealed + unichr(int(secretBinPart,2))

        secretRevealedEnd = ""
        while reverseResult.__len__() > 0:
            secretBinPart = reverseResult[-8:]
            reverseResult = reverseResult[:-8]
            secretRevealedEnd =  unichr(int(secretBinPart,2)) + secretRevealedEnd

        secretRevealed = secretRevealed + secretRevealedEnd
        print secretRevealed

        secretRevealedFile = open("secretRevealed.txt", "w+")
        secretRevealedFile.write(secretRevealed)
        secretRevealedFile.close()

        # for filename in self.ui.listOfFiles.findItems("",QtCore.Qt.MatchContains):
        #     secretPartFile = open(filename.text(),"rb")

        #     secretPart = secretFile.read()

            

    def openFile(self):
        filename = QtGui.QFileDialog.getOpenFileNames(self, 'Open File')[0]

        self.ui.listOfFiles.addItem(filename)