-
-
Notifications
You must be signed in to change notification settings - Fork 372
PDF Encryption and Decryption #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR creates a desktop GUI application for PDF encryption and decryption functionality, converting previously command-line-only scripts into a user-friendly Tkinter-based interface.
Key Changes:
- Created a complete GUI application with file browsing, password entry fields, and encrypt/decrypt buttons
- Merged core encryption/decryption logic into a single Python file with proper error handling
- Implemented intuitive user interface elements including file dialogs and message boxes
Comments suppressed due to low confidence (1)
PDF ENC & DEC/pdf_enc_dec.py:1
- The author credit label referenced in the PR description is missing from the GUI implementation. According to the description, there should be a permanent author credit at the bottom of the application window.
import tkinter as tk
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
PDF ENC & DEC/pdf_enc_dec.py
Outdated
# Try to decrypt using the provided password | ||
result = reader.decrypt(password) | ||
|
||
if result not in (1, 0): # 1 is correct password, 0 is empty password |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition is inverted. According to PyPDF documentation, decrypt()
returns 1 for correct password and 0 for incorrect password. The condition should be if result == 0:
to properly handle incorrect passwords.
if result not in (1, 0): # 1 is correct password, 0 is empty password | |
if result == 0: # 1 is correct password, 0 is incorrect password |
Copilot uses AI. Check for mistakes.
hey @DhanushNehru i just changed the login for dec kindly check my pr #496 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
writer.encrypt( | ||
user_password=user_password, | ||
owner_password=owner_password, | ||
permissions_flag=0xFFC0, # Common flag to restrict editing/copying for the user |
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number 0xFFC0 should be documented or replaced with named constants. Consider defining this as a constant with a descriptive name like RESTRICTED_USER_PERMISSIONS and documenting what specific permissions it grants/restricts.
Copilot uses AI. Check for mistakes.
# 1. ATTEMPT DECRYPTION WITH USER PASSWORD | ||
result = reader.decrypt(user_password) | ||
|
||
if result not in (1, 0): # 1 and 0 indicate successful decryption |
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers 1 and 0 for decryption success should be replaced with named constants or use the pypdf library's defined constants if available. This would make the code more readable and maintainable.
Copilot uses AI. Check for mistakes.
result = reader.decrypt(owner_password) | ||
|
||
# 3. CHECK FINAL DECRYPTION STATUS | ||
if result not in (1, 0): |
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same magic numbers 1 and 0 repeated. Consider defining constants like DECRYPTION_SUCCESS_CODES = (0, 1) at the module level and using them consistently throughout the decryption logic.
Copilot uses AI. Check for mistakes.
Summary
This Pull Request introduces a Graphical User Interface (GUI) for the PDF security scripts, making the tool more accessible and user-friendly. It also integrates the core encryption/decryption logic into a single application and adds a permanent author credit at the bottom of the window.
Description
This change converts the previously command-line-only Python scripts into a functional desktop application using the Tkinter library. Users can now easily select files, input passwords, and choose between the Encrypt and Decrypt operations via buttons, removing the need to edit the source code for configuration.
The application includes robust error handling to guide the user on necessary inputs and dependencies.
The changes are as follows:
pdf_enc_dec.py
: Merged encryption/decryption logic into a single, comprehensive Python file.cryptography
library for AES-256 to function correctly.Checks
in the repository
in the PR
Thank You,
Soriful Islam Sk