@'
from pathlib import Path
from shutil import copy2
from pypdf import PdfReader
folder = Path.home() / "Desktop" / "LR4"
pdf = folder / "LR4_PDF_encrypted.pdf"
print("FILE:", pdf)
print("EXISTS:", pdf.exists())
if not pdf.exists():
raise SystemExit("ERROR: File not found")
reader = PdfReader(str(pdf))
print("ENCRYPTED:", reader.is_encrypted)
if not reader.is_encrypted:
print("ERROR: PDF is not encrypted")
else:
empty = PdfReader(str(pdf)).decrypt("")
correct = PdfReader(str(pdf)).decrypt("P7d!")
print("EMPTY PASSWORD:", empty)
print("CORRECT PASSWORD:", correct)
if empty == 0 and correct != 0:
test = folder / "LR4_TEST_PROTECTED_2026.pdf"
copy2(pdf, test)
print("SUCCESS: Protection works")
print("TEST FILE:", test)
else:
print("ERROR: Password protection is incorrect")
'@ | py -