Exemplo n.º 1
0
 def decrypt(self):
     if len(self.passEdit.text()) > 0:
         fileNames = self.select_files('Hello please select files to decrypt')
         inc = 100//len(fileNames)
         completed = 0
         self.setStatusTip('Decrypting files...')
         for f in fileNames:
             encryption.decrypt_file(self.passEdit.text(), f)
             completed += inc
             self.statusLabel.setText('Decrypting ' + f+'...')
             self.progressBar.setValue(completed)
         self.progressBar.setValue(100)
         self.setStatusTip('Decryption complete')
Exemplo n.º 2
0
 def test_encrypt_decrypt_file(self):
     # test encrypting and decrypting a single file
     # get current value in the file
     content = None
     with open(self.test_file, "rb") as f:
         content = f.read()
     # file content should now be different
     encryption.encrypt_file(self.test_file, self.key)
     new_content = None
     with open(self.test_file_encrypted, "rb") as f:
         new_content = f.read()
     self.assertFalse(content == new_content)
     # decrypt and the content should be reverted
     encryption.decrypt_file(self.test_file_encrypted, self.key)
     new_content = None
     with open(self.test_file, "rb") as f:
         new_content = f.read()
     self.assertEqual(content, new_content)
    def downloadfile(self):
        selection = self.listbox.get(self.listbox.curselection())
        filenamecursor = cursor.execute('''SELECT filename FROM files WHERE filename=?''', (selection,))
        filename = "".join(cursor.fetchone())
        encryptedfile = filename + ".enc"
        urlcursor = cursor.execute('''SELECT url FROM files WHERE filename=?''', (selection,))
        posturl = cursor.fetchone()
        question = "Are you sure you want to download %s?" % (selection)
        result = tkMessageBox.askquestion("Download", question)
        chunks = []
        if result == 'yes':
            self.progressbar.config(mode="indeterminate")
            self.progressbar.start(interval=50)
            fileurl = "".join(posturl)
            submission = r.get_submission(url=fileurl, comment_limit=None, comment_sort='new')

            flat_comments = praw.helpers.flatten_tree(submission.comments)
            for comment in flat_comments:
                chunks.extend(["".join(comment.body)])

            filestring = re.sub('0-', '', re.sub('-[0-9]*-', '', "-".join(chunks[::-1])))
            nohex = binascii.unhexlify(filestring)
            path = tkFileDialog.askdirectory(parent=self, title='Choose a directory to save the file in')
            if path:
                with open(path + "/" + encryptedfile, 'wb') as f:
                    f.write(nohex)
                encryption.decrypt_file(self.key, path + "/" + encryptedfile)
                os.remove(path + "/" + encryptedfile)
                self.progressbar.stop()
                self.progressbar.config(mode="determinate")
                showinfo('OK', 'Download successful!')
                self.fetchfiles()
            else:
                self.progressbar.stop()
                self.progressbar.config(mode="determinate")
                self.fetchfiles()
Exemplo n.º 4
0
def print_columns(content):
    col_width = max(len(item) for row in content for item in row) + 1
    # Finner lengden på det lengste elementet i lista, legg til 1 som buffer.
    total_width = (col_width *3) +5
    print ""
    print "Skriver ut innhold i kolonner:"
    print "-" * total_width
    for row in content:
        print "".join(item.ljust(col_width) + "| " for item in row)
    print "-" * total_width

def sort_content(content):
        print ""
        print "Skriver ut alt innhold sortert:"
        combined = sorted(item for row in content for item in row)
        # Tar ut alle elementene i hver liste og legger det til i en ny liste sortert
        print "\n".join(word for word in combined)
        # Slår sammen elementene i listen med newline mellom hvert element

in_array = insert()
save(in_array)
key = raw_input("encryption key: ")
normal_file = "columns.csv"
encrypted_file = "columns.enc"
decrypted_file = "columns.decrypted"
encryption.encrypt_file(key, normal_file, encrypted_file)
encryption.decrypt_file(key, encrypted_file, decrypted_file)

# out_array = read()
# print_columns(out_array)
# sort_content(out_array)