Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Double loop?

by Dietz (Curate)
on Apr 30, 2005 at 22:01 UTC ( #452937=note: print w/ replies, xml ) Need Help??


in reply to Double loop?

Please don't delete code from your original question or change it otherwise without stating so.
When you have problems formatting content for PM please see Writeup Formatting Tips as frodo72 already stated.

Referring to offsite code (on your own server) isn't a good idea either, you would probably not keep it there forever, and other monks will get a different picture of this thread when you're changing the OP afterwards.

In fact, you changed even your code on your server, taking snippets from my last reply and now it looks like I just took out a few spaces and posted a neater version of yours.

I thought in posting a refactored, tidier and more compact version you could compare your efforts with someone elses try.

In your current version of your offsite code (http://as.switch2hosting.com/perl.txt) you took snippets and ideas from our replies and included following statement now:

You are free to customize this script as you wish, but do not
redistribute without written permission from TipoNaSoft.

Huh?
Is it really so special that one needs a written permission from you?

I'm adding your original code now below just that I don't stand here as a fool.

Original posting (OP) from RayQ:
#!/usr/bin/perl -T use Getopt::Std; use Digest::SHA qw(sha1_hex sha224_hex sha256_hex sha384_hex sha512_he +x); use Digest::MD5 qw(md5_hex); getopts('d:h:f:m:a'); my $dictionary = $opt_d; my $hash = $opt_h; my $mode = $opt_m; my $help = $opt_a; my $passfile = $opt_f; if($mode == ""){$mode = "md5";} my $algo = $mode; my %length; $length{'md5'} = 32; $length{'sha1'} = 40; $length{'sha224'} = 56; $length{'sha256'} = 64; $length{'sha384'} = 96; $length{'sha512'} = 128; if($help && (!$hash && !$passfile) || (!$hash && !$passfile)){help();e +xit(1);} &main; sub main { if($dictionary eq "") { $dictionary = "/usr/share/dict/words"; } if($hash) { if(length($hash) != $length{$algo}) { print STDERR "Invalid hash length!\nLength for an $algo ha +sh should be $length{$algo}!\nSee $0 -a for details.\n"; exit(1); } print "Cracking....\n"; } if($passfile eq "") { open DICT, $dictionary or die(" Could not open dictionary file : $dictionary. Please make sure the file exists and you have read access +to it. Error occured"); while(<DICT>) { chomp($_); if(hash($algo, $_) eq $hash) { print "\nMatch found!\nPlainText : " . $_ . "\n\n"; exit(0); } } } else { open PASS, $passfile or die(" Could not open password file : $passfile. Please make sure the file exists and you have read access +to it. Error occured"); print "Cracking....\n"; while(<PASS>) { open DICT, $dictionary or die(" Could not open dictionary file : $dictionary. Please make sure the file exists and you have read acc +ess to it. Error occured"); my $curpass = $_; chomp($curpass); chop($curpass); while(<DICT>) { my $word = $_; chomp($word); chop($word); #print $number."\n"; if(hash($algo, $word) eq $curpass) { print "$curpass :: $word\n"; close(DICT); } } } close(PASS); } exit(1); } sub help { print " Usage: $0 [-d dictionary] [-h hash|-f file] [-m mode]\n Crack [hash] or [file] using [mode] hashing, and [dictionary] +file.\n Currently, supported hashing methods are: MD5 SHA1 SHA224 SHA256 SHA384 SHA512 If no dictionary file is specified, /usr/share/dict/words will + be used.\n If no mode is specified, MD5 will be used. Example: $0 -h a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -m sha1 $0 -d /usr/local/Wordlist -h 098f6bcd4621d373cade4e832627b4f6 $0 -f /usr/bin/passwords.txt -d /usr/local/Wordlist \n"; } sub hash # hash($algo, $_) { if($_[0] eq "md5") { return md5_hex($_[1]); } elsif($_[0] eq "sha1") { return sha1_hex($_[1]); } elsif($_[0] eq "sha224") { return sha224_hex($_[1]); } elsif($_[0] eq "sha256") { return sha256_hex($_[1]); } elsif($_[0] eq "sha384") { return sha384_hex($_[1]); } elsif($_[0] eq "sha512") { return sha512_hex($_[1]); } }


Comment on Re: Double loop?
Download Code
Re^2: Double loop?
by RayQ (Initiate) on Apr 30, 2005 at 22:13 UTC
    Right, forgot I had changed it, lemme change it back xD
    That is just a fake disclaimer.
    Also, I did include it in code tags, and I had read that page. It just changed my tabbing everywhere, {'s were appearing where they shouldn't.
      ++ for inserting your original code in the OP again and for being so honest to say so.

      Keep at it!

      Cheers!

      That is just a fake disclaimer.

      IANAL, but AFAIK there is no such thing as a "fake" legal statement. While you are free to license your code under whichever license you choose, keep in mind that non-OSI compatible licenses will largely preclude others from citing your source in reply to any inquiries you might have.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-11-26 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls