Code Sample |
my @set = ( "r", "r", "t", "t", "a" .."d", "a" .."d" ); # ranges and lists to permute |
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\""; } } |