#!/usr/bin/perl use strict; use warnings; use Algorithm::Loops 'NestedLoops'; use Win32::OLE; my $file = $ARGV[0] or die "Usage: $0 "; # Important to use full path # Win32::OLE Example Program my $word; eval {$word = Win32::OLE->GetActiveObject('Word.Application')}; die "MSWord not installed" if $@; $word = Win32::OLE->new('Word.Application') or die "Can't start Word" if ! defined $word; $word->{Visible} = 1; my @key = (['a' .. 'z'], [0 .. 9], ['A' .. 'Z'], [0 .. 9]); my $next = NestedLoops(\@key); while (my @half = $next->()) { my $pass = Gen_Pass(@half); my $doc = $word->{Documents}->open({ 'FileName' => $file, 'PasswordDocument' => $pass, }); next if ! defined $doc; print "$pass\n", last; } sub Gen_Pass { my @pass = @_; my %conv = ( 1 => '!', 2 => '@', 3 => '#', 4 => '$', 5 => '%', 6 => '^', 7 => '&', 8 => '$', 9 => '(', 0 => ')', ); my ($third, $first) = @pass[2, 0]; push @pass, $pass[-1]; # Duplicate the 4th number push @pass, lc substr(++$third, 0, 1); # Increment 3rd char and lc it push @pass, $conv{$pass[1]}; # Convert 2nd num to a spec char push @pass, uc substr(++$first, 0, 1); # Increment 1st char and uc it return join '', @pass; }