#!/usr/bin/perl
sub generate_list{$_=q!$;=@_[0];$;--;$_='(0...9,"a"..."z","A"..."Z")';for($i=0;$i<=$;;$i++){$*.="\@t$i=$_;";$@.="for(\$c$i=0;\$c$i<=\$#t$i;\$c$i++){";}$.=$*.$@;$:='print';for($,=0;$,<=$;;$,++){$:.="\$t$,\[\$c$,\].";}$:.='$/;'.'}'x($;+1);return$..$:;!;eval eval}generate_list 2;
Hope you like it :)Not obfuscated, recursive and aimed at a slightly different target, but somewhat related is this thread of mine, with lots of following discussion that the OP may still find to be useful. Feel free to exand (or compress ;-) on it, just like Tanktalus did.
I am working on solving a similar problem with generation of rainbow tables (tables of strings and their hashes). I didn't want recursion because I needed restartability and arbitrary length.
I have something that works, albiet it needs a bit more work:
Basically, you could then solve your problem with:
Yeah, I know this is offtopic in an Obfu node, but I thought this might actually help you out. If you make useful modifications, I'd love to see them; my code's MIT licensed, though I haven't pasted that in yet -- basically, use to your heart's content, but give me credit.
package RainbowTable;
=pod ==========================================================================
=head1 NAME
RainbowTable - A module to assist in the creation of hash-based
rainbow tables
=head1 VERSION
This document describes RainbowTable version 0.01
=head1 SYNOPSIS
Generates a range of printable character combinations (such as might
be used for passwords) and converts them to hashes via a specifiable
hash function, caching the results for easy and fast searching later.
A hash type is required, other parameters are optional.
use RainbowTable;
#generate a table of MD5 hashes for all sets 1-10 chars in length
my $rainbow = RainbowTable->new(
hash => 'MD5', maxlength => 10, minlength=>1,
);
while ($rainbow->next) {
open my $fh, '>', $rainbow->hash or die($!);
print $fh $rainbow->string;
close $fh;
}
The iterative model is used, since it can take a I
use RainbowTable;
# I know we don't need a hash, but the module requires one.
my $generator = RainbowTable->new(
hash => 'MD5',
chars => [ ('A'..'Z'), ('a'..'z'), (0..9) ],
minlength => 3,
maxlength => 3,
);
while ($generator->next) {
print $generator->string, "\n";
}
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law
my $charset = '{'
. join(',', '0'..'9',
'A'..'Z',
'a'..'z')
. '}';
my @charlist = glob( $charset x 3 );
However, that's 238,328 elements. You might want to use glob in a scalar context, such as:
while my $list ( glob( $charset x 3 ) )
{
do_something_with($list);
}
-QM
--
Quantum Mechanics: The dreams stuff is made of
However, that's 238,328 elements. You might want to use glob in a scalar context
Unfortunately, using glob in a scalar context does not prevent it from pre-generating the entire list before giving you the first of them, so using it in a scalar context makes little or no difference to either the memory consumed, or the performance.
-QM
--
Quantum Mechanics: The dreams stuff is made of
I've thought about that, but it is difficult to see how to make it an true iterator without changing the interface to return some kind of 'handle'?
There is one other existing non-handle, scalar context iterator, each, and that is almost universally eshewed because of it's global nature.
There is one other existing non-handle, scalar context iterator, each, and that is almost univerally eshewed because of it's global nature.Yes. Besides the explicit handles of things like readdir and readline, the only other one I can think of is m//g, which is another beast entirely. It does have an explicit handle of sorts though.
-QM
--
Quantum Mechanics: The dreams stuff is made of
use strict;
use warnings;
our @c = (0..9,'a'..'z','A'..'Z');
build(7);
sub build {
my ($n, $s) = @_;
if (!--$n) { print "$s$_\n" for @c; return; }
build($n, "$s$_") for @c;
}
#! /usr/bin/perl
use strict;
use warnings;
chop $";
my @c = ('0'..'9', 'a'..'z', 'A'..'Z');
sub generate_list {
for(my @ii = (0) x ($_[0] + 1); $ii[0] == 0; do {
for(my $i = $#ii; ++$ii[$i] == @c; $ii[$i--] = 0) {}
} ) {
print "@c[@ii[1..$#ii]]\n";
}
}
generate_list 2;
perlmonks.org content © perlmonks.org and Anonymous Monk, blazar, BrowserUk, jdalbec, QM, radiantmatrix, RQZ, TedPride
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03