Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added references to the Wikipedia articles. Changes in a module's mai…

…n code.
  • Loading branch information...
commit b8394b72593024a391a89e3e95de8877ec470f65 1 parent 29e69f2
@digit4lfa1l digit4lfa1l authored
Showing with 79 additions and 14 deletions.
  1. +52 −9 lib/DDG/Goodie/CryptHashCheck.pm
  2. +27 −5 t/CryptHashCheck.t
View
61 lib/DDG/Goodie/CryptHashCheck.pm
@@ -1,14 +1,21 @@
package DDG::Goodie::CryptHashCheck;
-# ABSTRACT: Identifies cryptographic hash function type.
+# ABSTRACT: Identifies cryptographic hash type.
use DDG::Goodie;
+# A comprehensive reference for hashing functions from Wikipedia.
+
+use constant MD5HERF => "http://en.wikipedia.org/wiki/MD5#MD5_hashes";
+use constant SHA1HREF => "http://en.wikipedia.org/wiki/SHA-1#Example_hashes";
+use constant SHA2HREF => "http://en.wikipedia.org/wiki/SHA-2#Examples_of_SHA-2_variants";
+
zci is_cached => 1;
-triggers start => "hash","md5","sha";
+# Only one trigger enabled.
+triggers start => "hash";
primary_example_queries 'hash 624d420035fc9471f6e16766b7132dd6bb34ea62';
-secondary_example_queries 'md5 1f9b59a2390bb77d2c446837d6aeab067f01b05732735f47099047cd7d3e9f85';
+secondary_example_queries 'hash 1f9b59a2390bb77d2c446837d6aeab067f01b05732735f47099047cd7d3e9f85';
description 'Identifies cryptographic hash function type.';
name 'CryptHashCheck';
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CryptHashCheck.pm';
@@ -17,20 +24,56 @@ topics 'cryptography';
attribution github => ['https://github.com/digit4lfa1l', 'digit4lfa1l'];
+# Remainder function with links to the Wikipedia resources.
handle remainder => sub {
my ($md5) = /^[0-9a-f]{32}$/i;
- return 'This is a MD5 cryptographic hash.' if $md5;
+ if ($md5){
+ my $text = sprintf qq(This is a MD5 cryptographic hash.);
+ my $html = sprintf qq(This is a <a href="%s">MD5</a> cryptographic hash.),MD5HERF;
+
+ return $text, html => $html;
+ }
+
my ($sha1) = /^[0-9a-f]{40}$/i;
- return 'This is a SHA-1/40 cryptographic hash.' if $sha1;
+ if ($sha1){
+ my $text = sprintf qq(This is a SHA-1/40 cryptographic hash.);
+ my $html = sprintf qq(This is a <a href="%s">SHA-1/40</a> cryptographic hash.),SHA1HREF;
+
+ return $text, html => $html;
+ }
+
my ($sha224) = /^[0-9a-f]{56}$/i;
- return 'This is a SHA-2/224 cryptographic hash.' if $sha224;
+ if ($sha224){
+ my $text = sprintf qq(This is a SHA-2/224 cryptographic hash.);
+ my $html = sprintf qq(This is a <a href="%s">SHA-2/224</a> cryptographic hash.),SHA2HREF;
+
+ return $text, html => $html;
+ }
+
my ($sha256) = /^[0-9a-f]{64}$/i;
- return 'This is a SHA-2/256 cryptographic hash.' if $sha256;
+ if ($sha256){
+ my $text = sprintf qq(This is a SHA-2/256 cryptographic hash.);
+ my $html = sprintf qq(This is a <a href="%s">SHA-2/256</a> cryptographic hash.),SHA2HREF;
+
+ return $text, html => $html;
+ }
+
my ($sha384) = /^[0-9a-f]{96}$/i;
- return 'This is a SHA-2/384 cryptographic hash.' if $sha384;
+ if ($sha384){
+ my $text = sprintf qq(This is a SHA-2/384 cryptographic hash.);
+ my $html = sprintf qq(This is a <a href="%s">SHA-2/384</a> cryptographic hash.),SHA2HREF;
+
+ return $text, html => $html;
+ }
+
my ($sha512) = /^[0-9a-f]{128}$/i;
- return 'This is a SHA-2/512 cryptographic hash.' if $sha512;
+ if ($sha512){
+ my $text = sprintf qq(This is a SHA-2/512 cryptographic hash.);
+ my $html = sprintf qq(This is a <a href="%s">SHA-2/512</a> cryptographic hash.),SHA2HREF;
+
+ return $text, html => $html;
+ }
return;
};
View
32 t/CryptHashCheck.t
@@ -12,12 +12,34 @@ ddg_goodie_test(
[qw(
DDG::Goodie::CryptHashCheck
)],
- 'hash 5c0847eccfaeabf4a0207d42a2986992' => test_zci('This is a MD5 cryptographic hash.'),
- 'md5 ecaceaca62d6c47190ed6c6f94a298f28a46450fda0bd1ec8fc64bc4a7a8cd436791a35f3c4e339b7ae480c1b751f1c1' => test_zci('This is a SHA-2/384 cryptographic hash.'),
- 'sha b1d7eb51d4372c505446abca04835a101275e498' => test_zci('This is a SHA-1/40 cryptographic hash.'),
- 'hash 6286e0a5cbc030f7b2d105f594ae0afb9105c92175c6b07ff454734c23cd0bddfed77639fe59b68a70b8c78af27657f611cbe89c27f7a47b978fa9449808c19f' => test_zci('This is a SHA-2/512 cryptographic hash.'),
- 'md5 a8a35ab9036388fd42fe1d73d93ede7ec604044ba4753259fafbf718' => test_zci('This is a SHA-2/224 cryptographic hash.'),
+ 'hash 5c0847eccfaeabf4a0207d42a2986992' => test_zci(
+ qq(This is a MD5 cryptographic hash.),
+ html => qq(This is a <a href="http://en.wikipedia.org/wiki/MD5#MD5_hashes">MD5</a> cryptographic hash.),
+ answer_type => "crypthashcheck"
+ ),
+ 'hash ecaceaca62d6c47190ed6c6f94a298f28a46450fda0bd1ec8fc64bc4a7a8cd436791a35f3c4e339b7ae480c1b751f1c1' => test_zci(
+ qq(This is a SHA-2/384 cryptographic hash.),
+ html => qq(This is a <a href="http://en.wikipedia.org/wiki/SHA-2#Examples_of_SHA-2_variants">SHA-2/384</a> cryptographic hash.),
+ answer_type => "crypthashcheck"
+ ),
+ 'hash b1d7eb51d4372c505446abca04835a101275e498' => test_zci(
+ qq(This is a SHA-1/40 cryptographic hash.),
+ html => qq(This is a <a href="http://en.wikipedia.org/wiki/SHA-1#Example_hashes">SHA-1/40</a> cryptographic hash.),
+ answer_type => "crypthashcheck"
+ ),
+ 'hash 6286e0a5cbc030f7b2d105f594ae0afb9105c92175c6b07ff454734c23cd0bddfed77639fe59b68a70b8c78af27657f611cbe89c27f7a47b978fa9449808c19f' => test_zci(
+ qq(This is a SHA-2/512 cryptographic hash.),
+ html => qq(This is a <a href="http://en.wikipedia.org/wiki/SHA-2#Examples_of_SHA-2_variants">SHA-2/512</a> cryptographic hash.),
+ answer_type => "crypthashcheck"
+ ),
+ 'hash a8a35ab9036388fd42fe1d73d93ede7ec604044ba4753259fafbf718' => test_zci(
+ qq(This is a SHA-2/224 cryptographic hash.),
+ html => qq(This is a <a href="http://en.wikipedia.org/wiki/SHA-2#Examples_of_SHA-2_variants">SHA-2/224</a> cryptographic hash.),
+ answer_type => "crypthashcheck"
+ ),
);
done_testing;
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.