Quote (^thehatsrule^ @ Jan. 13 2008,21:00) |
About strcmp: The reason for this is that some compilers give -1 for a < string comparison, and a 1 for a > string comparison, and so a 0 is an exact match. IMO it's better to explicitly specify the comparison to 0 though to show it (as returning 0 can mean success as well like exit status) Interesting use of different languages... |
Quote |
What it looks like is you want a regex that detects 3 or more repeated adjacent chars as a substring? |
Code Sample |
dsl@box:~# ./cur.pl Skipping result with 3 chars ööö Skipping result with 3 chars aaa Current perm = aoc Found passphrase: art Terminated |
Code Sample |
#!/usr/bin/perl # curagacrack.pl use strict; use warnings; my $n = 30; # max len of passphrase my $j; my @set = ( "ö", "a" .."z" ); # ranges and lists to permute our $result = ""; my $printall = 0; # don't print perms #~ my $printall = 1; # print every perm sub print_perm { print "Current perm = $result\n"; } sub create_perm { my ($cur,$max)=@_; my ($k, $str); if($cur>=$max){ if ($printall == 1){ while ($k lt $cur){ $str .= "\b"; $k++; } print "$result$str"; } system("echo $result | 2>/dev/null openssl bf -pass stdin -d -in encryptedfile -out out.txt && file -b out.txt | grep -q '^ASCII text' && echo -n 'Found passphrase: ' && echo $result && kill 0"); return; } foreach my $c(@set){ substr($result,$cur,1)=$c; if (($max ge 3) && ($result =~ /$c{3}$/)) { print "Skipping result with 3 chars $result\n"; next; } create_perm($cur+1,$max); } } $SIG{'HUP'} = 'print_perm'; for ($j=1;$j<=$n;$j++){ create_perm(0,$j); } |