http://qs321.pair.com?node_id=285936


in reply to Character Combinations

viGuy,
I don't see this as un-ethical, but if the purpose is to provide a brute force crack against passwords - it is probably pretty silly. For instance - take a look at this thread for some numbers. If this is your goal, you would be much better off using a C compiled based program design for that effort. Even that is not un-ethical if the purpose is to ensure the integrity of the passwords of a given system you are responsible for the security of and you have ensured that it is legal. Since you didn't ask for that, I won't point you in the right direction.

Do you have something else in mind?

Cheers - L~R

Update: I was looking for an iterative solution an tye recommended Algorithm::Loops. Even though he hasn't uploaded it yet, the source is available here. My original sentiment stands, but this is how I would do it if I could think of a legitimate reason to do it.

#!/usr/bin/perl -w use strict; my @chars = ('a' .. 'z', 'A' .. 'Z', 0 .. 9); my $length = 8; my $get_combo = nestedLoops([ ([@chars]) x $length ]); my @list; while( @list= $get_combo->() ) { print "@list\n"; } # tye's nestedLoops code for future Algorithm::Loops sub nestedLoops { my( $loops, $params )= @_; my $code= $params && $params->{Code}; my @list; my $when= $params && $params->{OnlyWhen} || sub { @_ == @$loops }; my $i= -1; my @idx; my @vals= @$loops; my $iter= sub { while( 1 ) { # Prepare to append one more value: if( $i < $#$loops ) { $idx[++$i]= -1; $vals[$i]= $loops->[$i]->(@list) if 'CODE' eq ref $loops->[$i]; } # Increment furthest value, chopping if done there: while( @{$vals[$i]} <= ++$idx[$i] ) { # Return if all done: return if --$i < 0; pop @list; } $list[$i]= $vals[$i][$idx[$i]]; if( ! ref $when || $when->( @list ) ) { return @list; } } }; return $iter if ! $code; while( $iter->() ) { $code->( @list ); } }

On my Mom's mediocre computer, this would take 555 years to complete - give or take a few months :-)