Merge pull request #359 from parthasdey2304/master

added the code for pdf password decrypter
This commit is contained in:
Ayush Bhardwaj 2023-11-02 22:11:17 +01:00 committed by GitHub
commit a1490c49b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,74 @@
# Decrypt Your Password Protected pdf files Here
**Pdf-Password-Decrypter is a Python application that can be used to decrypt PDF files that are password-protected. This is optimised for Linux with apt**
# Features
+ Allows users to select a password-protected PDF file to be decrypted.
+ Provides an entry widget for the user to enter the password for the PDF file.
+ Allows users to enter a new name for the decrypted PDF file.
+ Creates a new PDF file that is not password-protected.
+ Allows users to view the decrypted PDF file in the Evince PDF viewer.
# Upcoming featuers
Some of the upcoming features include:
+ Editing the pdf directly.
+ Lock the pdf with a new password.
+ Unlocking encrypted pdf files with Brute Force attack.
+ Better UI design.
+ Replace tkinter with Kivy module of python.
+ Switch from PyPDF2 to some other python modules as it is no longer maintained.
# Pre-requisites
To run this Python program you would need these following packages
+ Python(version 3.7 or higher)
+ Tkinter python package
+ PyPDF2 python package(no longer maintained)
+ Evince pdf viewer
+ GIT
# Installation
You need to install all the prerequisites, follow the commands:
+ Installing python:
```
sudo apt install python3 -y
```
+ Installing Tkinter python package:
```
sudo apt install python3-tk -y
```
+ Installing PyPDF2 python package:
```
pip install pypdf2
```
+ Installing Evince pdf viewer:
```
sudo apt install evince -y
```
+ Installing Git:
```
sudo apt install git -y
```
# Usage
+ You need to first close this repository:
```
git clone https://github.com/parthasdey2304/Awesome-Python-Scripts.git
```
+ Getting inside the repository:
```
cd Awesome-Python-Scripts/PDF_Password_Decrypter
```
+ Running the python file:
```
python3 main.py
```
+ Done
# THANK YOU COMMUNITY!!!!

View File

@ -0,0 +1,82 @@
import os
import PyPDF2
from tkinter import *
from tkinter import filedialog
# Create a GUI window using tkinter
root = Tk()
root.configure(background='grey')
root.title('PDF Password Remover')
root.geometry('300x350')
# this is the method select_file which when invoked uses filedialog to open a file and store the path of the file in the variable file_path
def select_file():
global file_path
file_path = filedialog.askopenfilename()
# Creating a label to show the file path
Label(root, text=file_path, bg='grey', fg='white').pack(pady=10)
# this is the method decrypt which when invoked decrypts the file using the password provided by the user
def decrypt():
passwd = password.get() # getting the password from the entry widget
# Opening the PDF file with a password
pdf_file = open(file_path, 'rb')
pdf_reader = PyPDF2.PdfReader(pdf_file)
if pdf_reader.is_encrypted:
pdf_reader.decrypt(passwd)
# Create a new PDF file without password protection
pdf_writer = PyPDF2.PdfWriter()
length = len(pdf_reader.pages)
for page_num in range(length):
pdf_writer.add_page(pdf_reader.pages[length - page_num - 1])
# Creating a new file with the name provided by the user
new_file_name = new_file.get()+".pdf"
new_pdf_file = open(new_file_name, 'wb')
pdf_writer.write(new_pdf_file)
# Closing the files
pdf_file.close()
new_pdf_file.close()
# Showing the file in a tkinter window
show_pdf()
# this is a method that has a canvas of 500x700 resizeable to show the pdf file
# def show_pdf():
# pdf_file = open(new_file.get()+".pdf", 'rb')
# pdf_reader = PyPDF2.PdfReader(pdf_file)
# page = pdf_reader.pages[0]
# page_content = page.extract_text()
# print(page_content)
# pdf_file.close()
def show_pdf():
pdf_file = new_file.get()+".pdf"
os.system(f"evince {pdf_file}")
# Button to choose the file to be decrypted
Button(root, text='Select File', bg='white', font=('arial', 12, 'normal'), command=select_file).pack(pady=20)
# Label widget to show the password
Label(root, text='Password: ', bg='grey', fg = 'white', font=('arial', 12, 'normal')).pack()
# Entry widget to accept the password
password = Entry(root,text='Password', width=20, font=('arial', 12, 'normal'), show='*', border=2)
password.pack(pady=20)
# Label widget to show the name with which the new file would be stored
Label(root, text='New File Name:', bg='grey', fg = 'white', font=('arial', 12, 'normal')).pack()
# Entry widget to accept the name with which the new file would be stored
new_file = Entry(root,text='New File Name', width=20, font=('arial', 12, 'normal'), border=2)
new_file.pack(pady=20)
# Button to decrypt the file
Button(root, text='Decrypt', bg='white', font=('arial', 12, 'normal'), command=decrypt).pack(pady=20)
root.mainloop()

View File

@ -155,6 +155,7 @@ So far, the following projects have been integrated to this repo:
|[Zabbix API](zabbix_api)|[msg4sunny](https://github.com/msg4sunny)|
|[Zip password cracker](zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)|
|[Task Scheduler](Task-Scheduler)|[heysagnik](https://github.com/heysagnik)|
|[PDF Password Decypter](PDF_Password_Decrypter)|[parthasdey2304](https://github.com/parthasdey2304)|
## How to use:
- Clone/Download the directory and navigate to each folder. Or...