Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

BRUTEFORCE problem and a ?bug?

by xoddam (Novice)
on Mar 19, 2007 at 16:22 UTC ( [id://605516]=perlquestion: print w/replies, xml ) Need Help??

xoddam has asked for the wisdom of the Perl Monks concerning the following question:

First heres my first problem. I did program a simple NUMERIC BRUTE TOOL,

use warnings; use strict; print "Tell me your Password (numbers only, max 5 chars) \n"; my $lf = <stdin>; my $nummer = 0; print "$nummer \n"; until ($nummer == $lf) { $nummer = $nummer + 1; print "$nummer \n"; chomp($nummer) } print "GOTCHA $lf !!! \n";


Ok and now i want to do the same with ALPHABET. I really dont have an idea ho to make somethin like "A + 1 = B" ...

So i made it another way. Translated Alpabet to numbers from 0-24. And i got this source :

use warnings; use strict; my @alphabet = ("a", "b", "c" , "d", "e", "f", "g" , "h" , "i" , "j" , + "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v +" , "x" , "y" , "z"); my $nummer = 0; my $slovo; print "Tell me your pass (only small alphabet only ONE a-z)"; my $hladane = <stdin>; print "$alphabet[$nummer] \n"; $alphabet[$nummer] = $slovo; while ($slovo ne $hladane) { $nummer = $nummer + 1; print "$alphabet[$nummer]\n"; $alphabet[$nummer] = $slovo; chomp($hladane); } print "GOTCHA $hladane !!! \n";



It says all time only ERROR uninitialized value .. What the hell? Just want that if i give F to search it goes like A B C D E F - F STOP ! GOTCHA ...

And it does not stop, it does not find the letter ... only error and error :)

And the second problem is not big deal ... Have a look on the first program, test it and have a look on the END, AFTER GOTCHA > Number, it jumps to a new LINE and so the "!!!" stand alone one Line benath the others, what the hell? There is no "\n"

This two problems are destroying me today please if you have time help me .) - yea and my brute Alphabetical Tool searches only if there is one Letter .. i have no idea how to make it if there should be more ...

TY

Edit: g0n - replaced pre tags with code tags

Replies are listed 'Best First'.
Re: BRUTEFORCE problem and a ?bug?
by mreece (Friar) on Mar 19, 2007 at 16:43 UTC
    please use <code>..</code> tags so your code is easier to read and copy/paste.

    you have a couple of problems:

  • zero, you are missing "w" from your alphabet.
  • one, you should chomp $hladane immediately after reading it rather than at the end of the while loop.
  • two, your assignments $alphabet[$nummer] = $slovo are backwards, and you are slowly undefing each element of @alphabet.

    consider:

    use warnings; use strict; my @alphabet = ( "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" ); my $nummer = 0; my $slovo; print "Tell me your pass (only small alphabet only ONE a-z)"; my $hladane = <STDIN>; chomp $hladane; print "$alphabet[$nummer] \n"; $slovo = $alphabet[$nummer]; while ($slovo ne $hladane) { $nummer = $nummer + 1; print "$alphabet[$nummer]\n"; $slovo = $alphabet[$nummer]; } print "GOTCHA $hladane !!! \n";
Re: BRUTEFORCE problem and a ?bug?
by johngg (Canon) on Mar 19, 2007 at 16:45 UTC
    Firstly, please use <code> and </code> tags.

    You could set up your @alphabet using the range operator (..), like this

    my @alphabet = (q{a} .. q{z});

    You probably want to remove the newline (or whatever your platform uses) before doing any comparison

    chomp(my $hladane = <STDIN>);

    You are not assigning the first letter of the alphabet to $slovo but doing the reverse, change to

    $slovo = $alphabet[$nummer];

    Perl does allow you to increment letters

    $ perl -le '$let = q{a}; $let ++; print $let;' b $

    I hope this is of use.

    Cheers,

    JohnGG

Re: BRUTEFORCE problem and a ?bug?
by wfsp (Abbot) on Mar 19, 2007 at 16:43 UTC
    The ++ has some special magic!
    #!/usr/local/bin/perl use strict; use warnings; my $input = 'abcdef'; my $start = 'a'; while (1){ last if $start eq $input; $start++; } print "$input -> $start\n";
    output:
    abcdef -> abcdef
Re: BRUTEFORCE problem and a ?bug?
by polettix (Vicar) on Mar 19, 2007 at 16:45 UTC
    Use <code> tags around your code, and take a look to the Writeup Formatting Tips.

    If you have to generate a sequence of letters, this will do:

    my @alphabeth = 'a' .. 'z';

    You never initialise $slovo, but you keep using it, expecially in the while test. Moreover, are you sure that you get an ERROR and not a WARNING?

    If you want to increment a letter, it's as easy as doing this:

    my $letter = 'p'; $letter++; # Now $letter is 'q'

    Note that you should chomp immediately when you get the input letter, something along the lines:

    chomp(my $hladane = <STDIN>);
    This also means that you don't need to chomp() in the while loop.

    Regarding the newline problem, note that you never chomp() the $lf variable, that's where you get your newline from.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
      Ok got it now, thank you all ... And sorry for the tags ... Next time Ill use them ... GJ all ty
        No need for a "next time", you can go and edit your post to add the code tags as suggested by many. It would be nice if you did because the page is quite large.

        Flavio
        perl -ple'$_=reverse' <<<ti.xittelop@oivalf

        Don't fool yourself.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found