-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecryption tOol
33 lines (24 loc) · 891 Bytes
/
Decryption tOol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import shutil, os, PyPDF2, time
os.chdir(r"Working Directory")
source_dir = r"Source Directory"
dest_dir = r"Destnation Directory"
dest_dir2 = r"Temp Folder"
for root, dirs, files in os.walk(source_dir):
for file in files:
if file.endswith(".pdf"):
shutil.copy(os.path.join(root, file), dest_dir)
for i in os.listdir(dest_dir):
joinedfiles = open(os.path.join(dest_dir, i), "rb")
pdfreader = PyPDF2.PdfFileReader(joinedfiles)
pdfwriter = PyPDF2.PdfFileWriter()
for j in range(pdfreader.numPages):
pdfwriter.addPage(pdfreader.getPage(j))
pdfwriter.encrypt("hello9")
results = open(os.path.join(dest_dir, "encrypted"+i), "wb")
pdfwriter.write(results)
results.close()
joinedfiles.close()
time.sleep(2)
for i in os.listdir(dest_dir):
if not i.startswith("encrypted"):
os.remove(os.path.join(dest_dir, i))