Programming and Scripting :: C question



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...

i've always seen 'strcmp' as "string compare and tell me if there's a difference". i suppose 'strdiff' could be more appropriate.
Quote
What it looks like is you want a regex that detects 3 or more repeated adjacent chars as a substring?
Yes, exactly. And then skips them. This would also skip phrases that consist of only one character.

Thank you, very much. I hope I don't stress you too much :;):

Stress is my middle name lately (unfortunately).
Here it is with:

1. skips strings containing 3 adjacent same chars
2. only prints current perm on receipt of SIGHUP signal (eg pkill -1 cur.pl), but can print all perms if set $printall = 1.

It's not worth filtering out single char passphrases.  There's only one set of them.

So output on my test blowfish encrypted file (password = art) looks like:

Code Sample

dsl@box:~# ./cur.pl
Skipping result with 3 chars ööö
Skipping result with 3 chars aaa
Current perm = aoc
Found passphrase: art
Terminated


Current perm = aoc was where I sent it a pkill -1 cur.pl from another shell.

Comment out the line that prints skipped perms if you wish, it's for debugging.

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);
}

Thx. A typo maybe, if printall is set to 1 perl will print all tried options but also complain "using an unitialized value in string lt on line 27". Not a biggie, since I just tested with it set to 1, but will let it go with printall 0.

By strings consisting of 1 characters I meant strings like aaaaaaaaaaaa.

Next Page...
original here.