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) </ ... 8 9 10 11 12 [13] >/

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

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





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: April 15 2008,15:57 QUOTE

I'm not in a hurry, a custom solution is what I feel like testing anyway..

--------------
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: April 16 2008,20:59 QUOTE

One of the Monks on Perlmonks said we might like to try Algorithm::Combinatorics

This is XScode and so is supposed to be fast, and it does permutations with repetition so it doesn't generate redundant perms.
So you only put the desired ranges in once in the array @set.

It will generate all the perms with replacement, so I've put a regex filter in to skip perms containing 3 adjacent identical chars as Curaga wished.  Those perms still get generated but won't get tested on openssl.  Not sure which generation cost (redundant perms or perms with more than 3 adjacent chars) is more inefficient - a bit of math would work it it out I suppose.

EDIT:  this generates perms in the more or less expected alphabetic order so you can see just how far you are into a particular subset when you send it a SIGHUP to print.

I'd be interested in hearing how this seems to compare speed-wise.


Code Sample

#!/usr/bin/perl

# curagacrack2.pl
# Demonstration brute force password cracker #2 using use Algorithm::Combinatorics

use strict;
use warnings;
use Algorithm::Combinatorics qw(variations_with_repetition);

#==========================// SETTINGS // =========================


my @set = ( 'a'..'z', 'A'..'Z', '0'..'9' );

my $skip = 1; # filter: set to 1 to skip any perm containing 3 adjacent identical chars
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 = variations_with_repetition(\@set, $i);
my $c;
while ( $c = $p->next) {
$k++;
$perm = join("", @$c);
if ($printall == 1) {
print "$k $perm\n";
}
if (($skip == 1) && ($perm =~ /(.)\1\1/)){ next }
system("echo $perm | 2>/dev/null openssl bf -pass stdin -d -in encryptedfile -out out.txt && file -b out.txt | grep -qE '^ASCII.+text'") == 0 && die "Found passphrase \"$perm\"";

}

}

Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: April 18 2008,19:50 QUOTE

FYI, custom solutions notwithstanding: I do like fooling around with Perl on this - nonetheless I just compiled a C prog called "combina".

This not surprisingly does appear to be faster than the Perl, but I was pleasantly surprised to see not as much faster as I might have expected.  Rough "tests" suggest something like 20-50% faster, but that's just trying a few short passwords and it will depend on what password and the order im which the perms are generated, so it might average out to not much difference (or not).  XScode is,  in fact, interfacing with C libaries via Perl as I understand(?)  it so, indirecly, it is a way of using C.

Code Sample
time combina -a -A -n -p 1 -k 5  |  ( while read PW; do if 2>/dev/null openssl bf -pass pass:$PW  -d -in encryptedfile -out out.txt; then if file -b out.txt | grep -qE '^ASCII.+text'; then echo "Found passphrase $PW"; exit; else continue; fi; fi; done )


This found the highly challenging (not)  password "zz" in 20 sec.

The Perl above took 25 sec over the same name space.  There was a greater difference with other passwords.

(I'll post combina.uci to the repo anyway.)
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: May 07 2008,16:31 QUOTE

After some months of intense hacking away, and still not gotten even close, I decided to give up ;)

I was hoping I could find out the time needed to crack it, but it's way too good for that. I did prove it's really good though, and that it would take years even with a top notch comp.


--------------
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: May 08 2008,11:38 QUOTE

Got me looking at some Perl modules I'd never looked at anyway, which was interesting.
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) </ ... 8 9 10 11 12 [13] >/
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