These banks send credit card statements password protected by a combination of the card number, your name and date of birth. If you need to organize these on your PC, needing to remember the password for them can be a chore, especially if you have accounts at both banks. The pdfs they send out also dont have a meaningful name.
The following script automatically detects ICICI and HDFC bills, decrypts the files with the proper passwords, and renames them to a meaningful name. To use it, the only prerequisite is perl and qpdf. perl comes builtin for linux. For Windows, install Activestate or Strawberry perl, and qpdf for Windows.
You can also import a key to registry so that you can right click on the folder and decrypt all files within it.
Code:
#!/usr/bin/perl use strict; use warnings; use File::Basename; use Data::Dumper qw(Dumper); use feature 'say'; my $dirtoproc = ''; if (@ARGV) { # print Dumper \@ARGV; $dirtoproc = $ARGV[0]; } else { $dirtoproc = "."; } chdir $dirtoproc; use Cwd; my $PwICICI = 'youricicipwd'; my $PwHDFC = 'yourhdfcpwd'; opendir(DIR, "."); my @files = grep(//,readdir(DIR)); if (@files) { foreach my $file (@files) { # say "Processing..".$file; my ($basename, $parentdir, $extension) = fileparse($file, qr/\.[^.]*$/); if($file =~ m/.*_unlocked/) { # If already has name _unlocked, dont process say $file. ' was already processed earlier.'; } else { if($file =~ m/.*\d+-\d+-\d+.*/) { say "Found HDFC bill: $file"; my $cmd = 'qpdf -decrypt --password='.$PwHDFC.' "'.$file.'" "'. 'HDFC_'.$basename.'_unlocked.pdf"'; my $output = `$cmd`; print "$file >> ".$basename."_unlocked.pdf\n"; } elsif ($file =~ m/.*\sXXXX\sXXXX\s.*/) { say "Found ICICI bill: $file"; my $cmd = 'qpdf -decrypt --password='.$PwICICI.' "'.$file.'" "'. 'ICICI_'.$basename.'_unlocked.pdf"'; my $output = `$cmd`; print "$file >> ".$basename."_unlocked.pdf\n"; } elsif ($basename =~ m/\d+-\d+/) { print "Matched IOB!"; if ($file =~ m/IOB.*/) { say "..was already processed"; } else { use File::Copy; copy($file,"IOB_".$basename.'.pdf'); print "$file >> IOB_$basename.pdf\n"; } } } } }
Registry key: import.reg:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Decrypt known PDFs\Command] @="C:\\perlscripts\\decryptpdf\\runperl.cmd \"%1\""
And the file runperl.cmd:
C:\Strawberry\perl\bin\perl.exe C:\perlscripts\decryptpdf\decrypt.pl %1 pause
Joel G Mathew, known in tech circles by the pseudonym Droidzone, is an opensource and programming enthusiast.
He is a full stack developer, whose favorite languages are currently Python and Vue.js. He is also fluent in Javascript, Flutter/Dart, Perl, PHP, SQL, C and bash shell scripting. He loves Linux, and can often be found tinkering with linux kernel code, and source code for GNU applications. He used to be an active developer on XDA forums, and his tinkered ROMS used to be very popular in the early 2000s.
His favorite pastime is grappling with GNU compilers, discovering newer Linux secrets, writing scripts, hacking roms, and programs (nothing illegal), reading, blogging. and testing out the latest gadgets.
When away from the tech world, Dr Joel G. Mathew is a practising ENT Surgeon, busy with surgeries and clinical practise.