AutomateTheBoringStuff.Ch13.Projects package

Submodules

AutomateTheBoringStuff.Ch13.Projects.P1_encryptPDFparanoia module

Encrypt PDF paranoia

Using os.walk(), write a script that will go through every PDF in a folder (and its subfolders) and encrypt the PDFs using a password provided on the command line. Save each encrypted PDF with an _encrypted.pdf suffix added to the original filename.

Before deleting the original file, have the program attempt to read and decrypt the file to ensure that it was encrypted correctly.

Notes

  • Default folder is parent directory.
  • Default suffix is ‘_encrypted.pdf’.
  • Running in debug mode, uncomment to delete original file.
AutomateTheBoringStuff.Ch13.Projects.P1_encryptPDFparanoia.main()[source]

AutomateTheBoringStuff.Ch13.Projects.P2_decryptPDFparanoia module

Decrypt PDF paranoia

Write a program that finds all encrypted PDFs in a folder (and its subfolders) and creates a decrypted copy of the PDF using a provided password. If the password is incorrect, the program should print a message to the user and continue to the next PDF.

Note

  • Default input folder is parent directory.
  • Default output suffix is ‘_decrypted.pdf’.
AutomateTheBoringStuff.Ch13.Projects.P2_decryptPDFparanoia.main()[source]

AutomateTheBoringStuff.Ch13.Projects.P3_invitations module

Invitations

Say you have a text file of guest names. This guests.txt file has one name per line, as follows:

Prof. Plum
Miss Scarlet
Col. Mustard
Al Sweigart
RoboCop

Write a program that would generate a Word document with custom invitations.

Notes

  • Uses provided guests.txt file.
  • Default output file is invitations.docx.
AutomateTheBoringStuff.Ch13.Projects.P3_invitations.main()[source]

AutomateTheBoringStuff.Ch13.Projects.P4_PDFbreaker module

PDF breaker

Say you have an encrypted PDF that you have forgotten the password to, but you remember it was a single English word. Trying to guess your forgotten password is quite a boring task. Instead you can write a program that will decrypt the PDF by trying every possible English word until it finds one that works.

Create a list of word strings by reading dictionary.txt. Then loop over each word in this list, passing it to PyPDF2.PdfFileReader.decrypt(). If this method returns the integer 0, the password was wrong and your program should continue to the next password. If PyPDF2.PdfFileReader.decrypt() returns 1, then your program should break out of the loop and print the hacked password. You should try both the uppercase and lowercase form of each word.

Note

AutomateTheBoringStuff.Ch13.Projects.P4_PDFbreaker.main()[source]

Module contents