コード例 #1
0
ファイル: turanga-gtk.py プロジェクト: LeynerCordoba/turanga
    def decrypt_text(self, widget):
        text_path_obj = self.gui.get_object("txt_CTPath")
        text_pass_obj = self.gui.get_object("txt_CTPass")
        text_content = self.gui.get_object("txt_CTContent")

        path = text_path_obj.get_text()
        passw = text_pass_obj.get_text()
        tbuffer = text_content.get_buffer()

        content = tbuffer.get_text(
            tbuffer.get_start_iter(),
            tbuffer.get_end_iter(),
            True
        )

        if (path or content):
            if passw:
                if path:
                    trg = TurangaTextCryp(path, passw)

                elif content:
                    f = open(".temp-file", "w")
                    f.write(self.CTdata["TXT_REAL_CHARS"])
                    f.close()
                    trg = TurangaTextCryp(".temp-file", passw)

                result = trg.decryp()
                if result:
                    self.CTdata["TXT_REAL_CHARS"] = result
                    txt_buf = Gtk.TextBuffer()
                    txt_buf.set_text(unicode(result, errors='replace'))
                    text_content.set_buffer(txt_buf)
                else:
                    self.msg(
                        self.CryptTextWindow,
                        "El archivo no es un cifrado turanga!"
                    )
            else:
                self.msg(
                    self.CryptTextWindow,
                    "Password!?"
                )
        else:
            self.msg(
                self.CryptTextWindow,
                "Nothing to decrypt!"
            )
コード例 #2
0
ファイル: turanga-gtk.py プロジェクト: LeynerCordoba/turanga
    def crypt_text(self, widget):
        text_path_obj = self.gui.get_object("txt_CTPath")
        text_pass_obj = self.gui.get_object("txt_CTPass")
        text_content = self.gui.get_object("txt_CTContent")

        path = text_path_obj.get_text()
        passw = text_pass_obj.get_text()
        tbuffer = text_content.get_buffer()

        content = tbuffer.get_text(
            tbuffer.get_start_iter(),
            tbuffer.get_end_iter(),
            True
        )

        if (path or content) and passw:
            if path:
                trg = TurangaTextCryp(path, passw)
                fcryp = True

            elif content:
                temp = open(".temp_file", "w")
                temp.write(content)
                temp.close()

                trg = TurangaTextCryp(".temp_file", passw)
                fcryp = True
            else:
                fcryp = False

            if fcryp:
                result = trg.cryp()
                self.CTdata["TXT_REAL_CHARS"] = result
                #create text buffer
                text = Gtk.TextBuffer()
                text.set_text(unicode(result, errors='replace'))  # lint:ok
                #set result in textview
                text_content.set_buffer(text)

        elif not (path or content):
            self.msg(self.CryptTextWindow, "Nothing to crypt!")

        elif not passw:
            self.msg(self.CryptTextWindow, "Type any password!")