WDef
Group: Members
Posts: 798
Joined: Sep. 2005 |
|
Posted: Jan. 18 2008,16:38 |
|
Here is the permute module anyway, for use with the gtk2 .dsl extension which contains perl-5.8.7:
http://www.uploadhut.com/id169109/AlgorithmPermute-pm-5.8.7.dsl
Turns out my code wasn't broken after all, I just wasn't waiting long enough! Doesn't mean it couldn't be improveable. A few points:
1. It's fast. You can see how fast it is by commenting out the system call to openssl (which slows everything down) and turning printall on ( = 1). The Algorithm::Permute module is written in XS code so is efficient. This is the brand new version of the module (0.11).
2. It doesn't work though perms in lexicographic order ie the earlier program always started with the 1st char in the set etc. I don't follow the order at this stage.
3. As I discovered after adding one, there's no need for a filter to remove adjacent chars that are repeated say 3 times, since, in order to make it repeat chars, you just have to repeat the range or list in @set the number of times that you want to allow repetitions from that subset. We want to allow 2x reprtitions but not 3x, so just repeat the entire contents of your existing @set once.
So for eg in my test:
Code Sample | my @set = ( "r", "r", "t", "t", "a" .."d", "a" .."d" ); # ranges and lists to permute
|
will produce perms containing 'aa' but not 'aaa' etc.
Here it is:
Code Sample | #!/usr/bin/perl
# Demonstration brute force password cracker
use strict; use warnings; use Algorithm::Permute;
#==========================// SETTINGS // =========================
my @set = ( 'a'..'d', 'r', 't', 'a'..'d'); my $printall = 0; # set to 1 to print every perm my $startlen; my $endlen;
# Leave the following commented out to do all length perms within @set
#~ $startlen = 3; # begin processing with strings of length $startlen #~ $endlen = 5; # end processing with strings of length $endlen
#================================================================
my $perm = ""; my $k; my $i;
sub print_perm { print "Perm no. $k = $perm\n"; }
#================================// MAIN // =======================
$SIG{'HUP'} = 'print_perm'; # print current perm on receipt of sighup
$k = 0; my $setlen = $#set + 1;
# defaults unless (defined($startlen)) { $startlen = 1 } unless (defined($endlen)) { $endlen = $setlen }
unless ($startlen >= 1) { die "Error: startlen must be >= 1" } unless ($endlen >= $startlen) { die "Error: startlen must be <= endlen" } unless ($endlen <= $setlen) { die "Error: endlen must be <= $setlen" }
foreach $i ($startlen..$endlen) { my $p = new Algorithm::Permute([@set], $i); my @res; while (@res = $p->next) { $k++; $perm = join("", @res); if ($printall == 1) { print "$k $perm\n"; } system("echo $perm | 2>/dev/null openssl bf -pass stdin -d -in encryptedfile -out out.txt && file -b out.txt | grep -q '^ASCII text'") == 0 && die "Found passphrase \"$perm\"";
}
}
|
EDIT1: added perm counter to sighup print EDIT2: added variable length string ranges and defaults
|