Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (13) </ ... 2 3 4 5 6 [7] 8 9 10 11 12 ... >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: C question, loops< Next Oldest | Next Newest >
humpty Offline





Group: Members
Posts: 655
Joined: Sep. 2005
Posted: Jan. 14 2008,15:00 QUOTE

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.
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Jan. 14 2008,15:56 QUOTE

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


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Jan. 14 2008,23:50 QUOTE

Stress is my middle name lately (unfortunately).
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Jan. 15 2008,17:10 QUOTE

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);
}
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Jan. 16 2008,16:01 QUOTE

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.


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
64 replies since Jan. 12 2008,13:35 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (13) </ ... 2 3 4 5 6 [7] 8 9 10 11 12 ... >/
reply to topic new topic new poll
Quick Reply: C question

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code