diff --git a/bin/decrypt-pdf b/bin/decrypt-pdf index f9a5053..6ea4d4c 100644 --- a/bin/decrypt-pdf +++ b/bin/decrypt-pdf @@ -12,21 +12,23 @@ fi passwords=($(cat "$password_file")) - encryption_info=$(qpdf --show-encryption "$input_file" 2>&1) +declare -i counter=0 + if [[ $encryption_info == *"Incorrect password supplied"* ]]; then echo "PDF is encrypted. Trying passwords..." for password in "${passwords[@]}"; do + let counter+=1 # increment qpdf --warning-exit-0 --password="$password" --decrypt "$input_file" "$output_file" >/dev/null 2>&1 if [ $? -eq 0 ]; then - echo "PDF decrypted successfully with password: $password" + echo "PDF decrypted successfully with password on attempt $counter" echo "Output saved to $output_file" exit 0 else - echo "Failed to decrypt the PDF with password: $password" + echo "Attempt $counter: Failed to decrypt the PDF" fi done