Results 1 to 9 of 9

Thread: Hash file #Perl

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Posts
    5

    Hash file #Perl

    Code:
    #!perl
    # hash.pl (written by n0m3rcy)
    use strict;
    use Digest::MD5;
    use Digest::SHA1;
    
    my $file = shift || die "Must enter a filename.\n";
    
    if (-e $file) { 
    	my ($md5,$sha) = hash($file);
    	print "File : ".$file."\n";
    	print "MD5  : ".$md5."\n";
    	print "SHA-1: ".$sha."\n";
    }
    else {
    	print "$file not found.\n";
    }
    
    
    #------------------------------------------
    # hash subroutine
    #------------------------------------------
    sub hash {
    	my $file = $_[0];
    	my $md5;
    	my $sha;
    	
    	eval {
    # Generate MD5 hash
    		open(FILE, $file);
      	binmode(FILE);
    		$md5 = Digest::MD5->new->addfile(*FILE)->hexdigest;
    		close(FILE);
    # Generate SHA-1 hash
    		open(FILE, $file);
      	binmode(FILE);
    		$sha = Digest::SHA1->new->addfile(*FILE)->hexdigest;
    		close(FILE);
    	};
    	($@) ? (return $@) : (return ($md5,$sha));	
    }
    Regards,
    n0m3rcy
    n0m3rcy(); BEG me or DIE
    contact: irc://irc.milw0rm.com #milw0rm

  2. #2
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    This is neat and all, but your commenting needs something...

    #------------------------------------------
    # hash subroutine
    #------------------------------------------

    Kind of obvious isn't it?

    But then it's also not your code... unless you are providing the examples to safari's informit book site.

    http://safariexamples.informit.com/0...h5code/hash.pl

    Your download/copy/paste skills are excellent! Well done!
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    5
    hey, thanks for comment

    this mine, i gave it for somebody, i didn't know if he changed it

    really, it's mine
    n0m3rcy(); BEG me or DIE
    contact: irc://irc.milw0rm.com #milw0rm

  4. #4
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    Really? You gave it to Harlan Carvey for use in his Windows Forensics and Incident Recovery book? And he's using the code with your claim to ownership stripped?

    And monkeys will start flying out of my butt. Next time at least modify more code than adding your name to it before you try to pass it off as yours to look cool.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  5. #5
    Junior Member
    Join Date
    Jan 2006
    Posts
    5
    You'll see if it's mine or not, by my projects and codes soon

    Regards,
    n0m3rcy(); BEG me or DIE
    contact: irc://irc.milw0rm.com #milw0rm

  6. #6
    Banned
    Join Date
    Aug 2001
    Location
    Yes
    Posts
    4,424
    Windows Forensics and Incident Recovery. Harlan Carvey. Listing 5-12. p. 229
    Perl can be used to create scripts that compute MD5 and SHA-1 hashes for files. Hash.pl, the Perl script illustrated in Listing 5-12, is such a script.
    Look at that... it says Copyright 2005 by Pearson Education, Inc. in my copy...

    n0m3rcy > stop bullshitting Juridian... your only way out was claiming you're Carvey himself, but unfortunately for you, Carvey is not an idiot and knows how to spell...

  7. #7
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    But, I'd still love to see more of your code. It should be loads of fun. =) I dabble in that software development stuff myself from time to time.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  8. #8
    Senior Member
    Join Date
    Dec 2003
    Location
    Pacific Northwest
    Posts
    1,675
    Originally posted here by n0m3rcy
    You'll see if it's mine or not, by my projects and codes soon
    Just a footnote: If it has been written, whether it is deals with the various programming languages, all aspects of security, etc., someone in here has probably already, read it, done a report on it, and referenced it. So don't try to pull the wool over someone's eyes. Tonight was a classic example, you hit the jackpot, two members even knew the exact code, and Neg even had the page and figure number. That's Carvey's work not yours.

    When you code, just give credit where it is due!

    cheers
    Connection refused, try again later.

  9. #9
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,188
    Hey,n0m3rcy

    As a matter of "style", just posting a block of code isn't that cool, some form of commentary would make it look a lot better............


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •