in reply to Re: Brute Force Algorithm with Perl reg exprs?
in thread Brute Force Algorithm with Perl reg exprs?

Oops, it's been more than a week. Here's the promised code
use strict; use warnings; sub crack { my $hint = shift; my $target = shift; my $salt = substr($target, 0, 2); my @chars = @_; my $base = @chars; my $passwd; use integer; for (my $num_chars=0; ; $num_chars++) { for (my $enc=0; ; $enc++) { my $i = $enc; my $pad = ''; for (1..$num_chars) { my $idx = $i % $base; $i = $i / $base; $pad .= $chars[$idx]; } # Go add a character. last if $i; #$pad = reverse $pad; for my $pos (0..$num_chars) { $passwd = $pad; substr($passwd, $pos, 0, $hint); return $passwd if crypt($passwd, $salt) eq $target; } } } } my @chars = ('a'..'z', 'A'..'Z', '0'..'9'); print crack('12', crypt('d12e', 'AA'), @chars), "\n"; print crack('1234', crypt('aa12345', 'AA'), @chars), "\n";