Write a Python program to crack the password of the attached encrypted PDF document ("ConfidentialDoc.pdf") using the brute force attack method. The brute force attack involves creating a password from every combination of a string taken from a character set.
[Hint: The actual password used to encrypt the PDF document is of length 4 characters and consists of a combination of lowercase letters and numbers. So, the character set is lowercase letters from 'a' to 'z' and numbers from 0 to 9. The program must also extract the text from the PDF document and provide the correct password and the extracted text in the output section below.
The below program will give you an idea of how to generate all possible combinations of passwords from a character set of uppercase letters and numbers with a password length of 2 characters. I suggest you run this sample code and see the output first.
import itertools
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for item in itertools.product(charset, repeat=2):
temp_str = ""
password = temp_str.join(item)
print(password)
Note: I have chosen the password in such a way that the correct program should be able to crack it in less than 2 minutes. If your program is taking more than 2 minutes to crack it, then there might be a problem with your code. Also, I advise you to break the loop once the password is matched and the text is extracted.