Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
P is for Practical
 
PerlMonks  

Password Solver 2

by sulfericacid (Deacon)
on Jul 08, 2009 at 22:59 UTC ( #778436=perlquestion: print w/ replies, xml ) Need Help??
sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

Hello again, Monks.

Some of you may remember my recent post regarding password solving. It worked, to some extent, but it gave me a good base on passwords in general.

I come again today to ask advice on another technique I'd like to try. I'd like to do a sequential scan to see if it will improve my last password solver by not producing duplicates.

You'll see my framework below. I'm mapping out each character to a set value (granted the list will be longer for A-Z, digits, special chars). My idea is to determine what the last character is and ++ it's value. Once it's value == the max number of characters in my %mapping, it'll set it's count back to 1 and it'll push the letter to the left up one character.

Ie:

... aay aaz aba abb
I'm trying to start with one digit "a" and try each character in my list, once each character is tested it'll prepend another character. From there it'll try all the combinations again and again thus trying every password combination from the characters given.

I'm having a problem getting the logic on paper. As this is a learning experience (and it REALLY is, I haven't used Perl intimately for almost 2 years now because my work switched my job around) I don't want someone to slap together code that will do the whole process. I'm just looking for advice/pointers on how to start making my iterations.

#!/usr/bin/perl use warnings; use strict; my $password = "pass"; my %mapping = ( "a" => "1", "b" => "2", "c" => "3", "d" => "4", "e" => + "5", "f" => "6", "g" => "7", "h" => "8", "i" => "9", "j" => "10", "k" = +> "11", "l" => "12", "m" => "13", "n" => "14", "0" => "15", "p" => "16", "q" => "17 +", "r" => "18", "s" => "19", "t" => "20", "u" => "21", "v" => "22", "w" => "23 +", "x" => "24", "y" => "25", "z" => "26" );


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Comment on Password Solver 2
Select or Download Code
Re: Password Solver 2
by ikegami (Pope) on Jul 08, 2009 at 23:25 UTC

    Note that if you're only dealing with letters, you can use ++ on strings.

    $ perl -e'$g="a"; print $g++, " " while $g ne 'cw'; print "\n"' a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af +ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc +bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz +ca cb cc cd ce cf cg ch ci cj ck cl cm cn co cp cq cr cs ct cu cv

    Otherwise, your mapping is backwards. You should be working with numbers (indexes into @mapping), then mapping to the characters.

    my @mapping = ('a'..'z'); my $guess = join '', @mapping[ @guess ];

    It might be a bit faster to build $guess relative to the previous value rather than building it from scratch every time, but that's easy to change later.

Re: Password Solver 2
by AnomalousMonk (Monsignor) on Jul 09, 2009 at 00:21 UTC
    If I correctly understand your requirement, for a character set  'a' .. 'z' you want to iterate first through all single-character combinations 'a' to 'z', then through all two-character combinations 'aa' to 'zz', and so on.

    Contrary to your request, the following is a more-or-less complete solution using iterators, so don't look at it until you have tried some solutions of your own.

    File: Bruterate.pm

    File: crack_pw_2.pl

    Output:

    >perl crack_pw_2.pl usage: perl crack_pw_2.pl password >perl crack_pw_2.pl z found password 'z' in 0 seconds with 26 tries >perl crack_pw_2.pl zz found password 'zz' in 0 seconds with 1517 tries >perl crack_pw_2.pl xy5 found password 'xy5' in 3 seconds with 97967 tries
Re: Password Solver 2
by apl (Monsignor) on Jul 09, 2009 at 13:16 UTC
    In addition to what others said, if you really needed
    my %mapping = ( "a" => "1", "b" => "2", "c" => "3", "d" > "4", "e" => "5", "f" => "6", "g" => "7", "h" => "8", "i" => "9", "j" => "10", "k" => "11", "l" => "12", "m" => "13", "n" => "14", "0" => "15", "p" => "16", "q" => "17", "r" => "18", "s" => "19", "t" => "20", "u" => "21", "v" => "22", "w" => "23", "x" => "24", "y" => "25", "z" => "26"
    you could replace it with (untested)
    my $new_ch = ( $old_ch - 'a' ) + 1;
    or
    my $new_ch = chr( ord( $old_ch ) - 96 );
    Perl golfers, and those more confident than me, can reduce itr further.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://778436]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-04-17 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (441 votes), past polls