Skip to content

Instantly share code, notes, and snippets.

@warewolf
Created April 3, 2015 22:00
Show Gist options
  • Select an option

  • Save warewolf/bc4000081ff20323e52a to your computer and use it in GitHub Desktop.

Select an option

Save warewolf/bc4000081ff20323e52a to your computer and use it in GitHub Desktop.
Today I learned about Scalar::Util::dualvar, and used it to my advantage.
#!/usr/bin/perl
use strict;
use warnings;
use Scalar::Util qw(dualvar);
use List::Util qw(first);
use constant {
md5 => dualvar(length('62e2b06482fc7c4f4312797c81bf102a'),"md5"),
sha1 => dualvar(length('59ad3fe46fa061bfd690e0bce261a4cb37a83e51'),"sha1"),
sha256 => dualvar(length('d6d307d596a85d583f722b8a05005cf0df6739c9a7a037ca9339d3b21b0a21b5'),"sha256"),
sha384 => dualvar(length('4273ae07d6db5576f1492fc340d0235b1a2cd2f048b21851bf3a807c515fc60be0e66d8c885c45580305146cf239497e'),"sha384"),
sha512 => dualvar(length('c1396003c38aaed98d5d8586a0b7e56d1bfae4369f4befd852c2a6bae79d6a73cb308e4b49ea1df3fa8c38793bb88ae0446056fb13c4c71928346fbc699720b2'),"sha512"),
ripemd160 => dualvar(length('9233d3756b9a0c23d720933133b5b92a16911a92'),"ripemd160"),
};
my @hashes = qw(d02d333c594f43280fdd8b728ba6129bc4bab4f0 884ed0bdce550e39f1026120cb0c57401199e32934205b953af8d01e442ddff1 mtfnpy);
foreach my $hash (@hashes) {
my $hashtype = first { length($hash) == $_ } (sha1,sha256,sha384,sha512,md5,ripemd160);
if ($hashtype) {
printf "Hash %s is hash type %s, length %d\n",$hash,$hashtype,$hashtype;
} else {
printf "Hash %s is UNKNOWN, length %d\n",$hash,length($hash);
}
}
@warewolf
Copy link
Copy Markdown
Author

warewolf commented Apr 3, 2015

Well fuck.

RIPEMD160(/etc/passwd)= 9233d3756b9a0c23d720933133b5b92a16911a92
     SHA1(/etc/passwd)= 59ad3fe46fa061bfd690e0bce261a4cb37a83e51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment