2012-12-01 13:56:06 -08:00
|
|
|
package DDG::Goodie::CryptHashCheck;
|
2012-12-04 12:00:51 -08:00
|
|
|
# ABSTRACT: Identifies cryptographic hash type.
|
2012-12-01 13:56:06 -08:00
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2012-12-01 13:56:06 -08:00
|
|
|
use DDG::Goodie;
|
|
|
|
|
2012-12-04 12:00:51 -08:00
|
|
|
# A comprehensive reference for hashing functions from Wikipedia.
|
|
|
|
|
2012-12-10 14:08:30 -08:00
|
|
|
use constant MD5HERF => "http://en.wikipedia.org/wiki/MD5";
|
|
|
|
use constant SHA1HREF => "http://en.wikipedia.org/wiki/SHA-1";
|
|
|
|
use constant SHA2HREF => "http://en.wikipedia.org/wiki/SHA-2";
|
2012-12-16 11:11:02 -08:00
|
|
|
use constant SHA3HREF => "http://en.wikipedia.org/wiki/SHA-3";
|
2012-12-04 12:00:51 -08:00
|
|
|
|
2012-12-01 13:56:06 -08:00
|
|
|
zci is_cached => 1;
|
|
|
|
|
2012-12-04 12:00:51 -08:00
|
|
|
# Only one trigger enabled.
|
|
|
|
triggers start => "hash";
|
2012-12-01 13:56:06 -08:00
|
|
|
|
|
|
|
primary_example_queries 'hash 624d420035fc9471f6e16766b7132dd6bb34ea62';
|
2012-12-04 12:00:51 -08:00
|
|
|
secondary_example_queries 'hash 1f9b59a2390bb77d2c446837d6aeab067f01b05732735f47099047cd7d3e9f85';
|
2012-12-01 13:56:06 -08:00
|
|
|
description 'Identifies cryptographic hash function type.';
|
|
|
|
name 'CryptHashCheck';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CryptHashCheck.pm';
|
|
|
|
category 'computing_tools';
|
|
|
|
topics 'cryptography';
|
|
|
|
|
|
|
|
attribution github => ['https://github.com/digit4lfa1l', 'digit4lfa1l'];
|
|
|
|
|
2014-10-28 11:36:15 -07:00
|
|
|
# Remainder function with links to the Wikipedia resources.
|
2012-12-01 13:56:06 -08:00
|
|
|
|
|
|
|
handle remainder => sub {
|
|
|
|
my ($md5) = /^[0-9a-f]{32}$/i;
|
2012-12-04 12:00:51 -08:00
|
|
|
if ($md5){
|
2012-12-10 14:08:30 -08:00
|
|
|
my $text = sprintf qq(This is a 128 bit MD5 cryptographic hash.);
|
2014-10-28 11:36:15 -07:00
|
|
|
my $html = sprintf qq(This is a 128 bit <a href="%s">MD5</a> cryptographic hash.),MD5HERF;
|
|
|
|
|
|
|
|
return $text, html => $html;
|
2012-12-04 12:00:51 -08:00
|
|
|
}
|
|
|
|
|
2012-12-01 13:56:06 -08:00
|
|
|
my ($sha1) = /^[0-9a-f]{40}$/i;
|
2012-12-04 12:00:51 -08:00
|
|
|
if ($sha1){
|
2012-12-10 14:08:30 -08:00
|
|
|
my $text = sprintf qq(This is a 160 bit SHA-1 cryptographic hash.);
|
2014-10-28 11:36:15 -07:00
|
|
|
my $html = sprintf qq(This is a 160 bit <a href="%s">SHA-1</a> cryptographic hash.),SHA1HREF;
|
|
|
|
|
|
|
|
return $text, html => $html;
|
2012-12-04 12:00:51 -08:00
|
|
|
}
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2012-12-01 13:56:06 -08:00
|
|
|
my ($sha224) = /^[0-9a-f]{56}$/i;
|
2012-12-04 12:00:51 -08:00
|
|
|
if ($sha224){
|
2012-12-16 11:11:02 -08:00
|
|
|
my $text = sprintf qq(This is a 224 bit SHA-2/SHA-3 cryptographic hash.);
|
2014-10-28 11:36:15 -07:00
|
|
|
my $html = sprintf qq(This is a 224 bit <a href="%s">SHA-2</a>/<a href="%s">SHA-3</a> cryptographic hash.),SHA2HREF,SHA3HREF;
|
|
|
|
|
|
|
|
return $text, html => $html;
|
2012-12-04 12:00:51 -08:00
|
|
|
}
|
|
|
|
|
2012-12-01 13:56:06 -08:00
|
|
|
my ($sha256) = /^[0-9a-f]{64}$/i;
|
2012-12-04 12:00:51 -08:00
|
|
|
if ($sha256){
|
2012-12-16 11:11:02 -08:00
|
|
|
my $text = sprintf qq(This is a 256 bit SHA-2/SHA-3 cryptographic hash.);
|
2014-10-28 11:36:15 -07:00
|
|
|
my $html = sprintf qq(This is a 256 bit <a href="%s">SHA-2</a>/<a href="%s">SHA-3</a> cryptographic hash.),SHA2HREF,SHA3HREF;
|
|
|
|
|
|
|
|
return $text, html => $html;
|
2012-12-04 12:00:51 -08:00
|
|
|
}
|
|
|
|
|
2012-12-01 13:56:06 -08:00
|
|
|
my ($sha384) = /^[0-9a-f]{96}$/i;
|
2012-12-04 12:00:51 -08:00
|
|
|
if ($sha384){
|
2012-12-16 11:11:02 -08:00
|
|
|
my $text = sprintf qq(This is a 384 bit SHA-2/SHA-3 cryptographic hash.);
|
2014-10-28 11:36:15 -07:00
|
|
|
my $html = sprintf qq(This is a 384 bit <a href="%s">SHA-2</a>/<a href="%s">SHA-3</a> cryptographic hash.),SHA2HREF,SHA3HREF;
|
|
|
|
|
|
|
|
return $text, html => $html;
|
2012-12-04 12:00:51 -08:00
|
|
|
}
|
|
|
|
|
2012-12-01 13:56:06 -08:00
|
|
|
my ($sha512) = /^[0-9a-f]{128}$/i;
|
2012-12-04 12:00:51 -08:00
|
|
|
if ($sha512){
|
2012-12-16 11:11:02 -08:00
|
|
|
my $text = sprintf qq(This is a 512 bit SHA-2/SHA-3 cryptographic hash.);
|
2014-10-28 11:36:15 -07:00
|
|
|
my $html = sprintf qq(This is a 512 bit <a href="%s">SHA-2</a>/<a href="%s">SHA-3</a> cryptographic hash.),SHA2HREF,SHA3HREF;
|
|
|
|
|
|
|
|
return $text, html => $html;
|
2012-12-04 12:00:51 -08:00
|
|
|
}
|
2014-10-28 11:36:15 -07:00
|
|
|
return;
|
2012-12-01 13:56:06 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
1;
|