From a4b7a052b8389d63e67e762f2e892074a6a3948d Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Thu, 3 Jan 2019 00:12:39 +0100 Subject: [PATCH] Added test modules for mode 22, 30 and 40 --- tools/test_modules/m00022.pm | 78 ++++++++++++++++++++++++++++++++++++ tools/test_modules/m00030.pm | 45 +++++++++++++++++++++ tools/test_modules/m00040.pm | 45 +++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 tools/test_modules/m00022.pm create mode 100644 tools/test_modules/m00030.pm create mode 100644 tools/test_modules/m00040.pm diff --git a/tools/test_modules/m00022.pm b/tools/test_modules/m00022.pm new file mode 100644 index 000000000..1bbe20ec0 --- /dev/null +++ b/tools/test_modules/m00022.pm @@ -0,0 +1,78 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::MD5 qw (md5); + +sub module_constraints { [[0, 256], [1, 11], [0, 35], [1, 11], [1, 35]] } + +sub module_generate_hash +{ + my $itoa64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + my $salt_suffix = "Administration Tools"; + + my $word = shift; + my $salt = shift; + + my $pass = sprintf ("%s:%s:%s", $salt, $salt_suffix, $word); + + my $hash_buf = md5 ($pass); + + my $res = ""; + + for (my $pos = 0; $pos < 16; $pos += 2) + { + my $octet1 = ord (substr ($hash_buf, $pos + 0, 1)); + my $octet2 = ord (substr ($hash_buf, $pos + 1, 1)); + + my $num = ($octet1 <<8 & 0xff00) | ($octet2 & 0xff); + + my $idx1 = $num >> 12 & 0x0f; + my $idx2 = $num >> 6 & 0x3f; + my $idx3 = $num & 0x3f; + + $res = $res . substr ($itoa64, $idx1, 1) . substr ($itoa64, $idx2, 1) . substr ($itoa64, $idx3, 1); + } + + my $obfuscate_str = "nrcstn"; + my @obfuscate_pos = (0, 6, 12, 17, 23, 29); + + foreach my $pos (keys @obfuscate_pos) + { + my $idx = $obfuscate_pos[$pos]; + my $before = substr ($res, 0, $idx); + my $char = substr ($obfuscate_str, $pos, 1); + my $after = substr ($res, $idx); + + $res = sprintf ("%s%s%s", $before, $char, $after); + } + + my $hash = sprintf ("%s:%s", $res, $salt); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $salt; + return unless defined $word; + + $word = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word, $salt); + + return ($new_hash, $word); +} + +1; diff --git a/tools/test_modules/m00030.pm b/tools/test_modules/m00030.pm new file mode 100644 index 000000000..ec6c20d93 --- /dev/null +++ b/tools/test_modules/m00030.pm @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::MD5 qw (md5_hex); +use Encode; + +sub module_constraints { [[0, 127], [0, 255], [0, 27], [0, 54], [0, 27]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $digest = md5_hex (encode ("UTF-16LE", $word) . $salt); + + my $hash = sprintf ("%s:%s", $digest, $salt); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $salt; + return unless defined $word; + + $word = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word, $salt); + + return ($new_hash, $word); +} + +1; diff --git a/tools/test_modules/m00040.pm b/tools/test_modules/m00040.pm new file mode 100644 index 000000000..d9c8e15fc --- /dev/null +++ b/tools/test_modules/m00040.pm @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::MD5 qw (md5_hex); +use Encode; + +sub module_constraints { [[0, 127], [0, 127], [0, 27], [0, 55], [0, 27]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $digest = md5_hex ($salt . encode ("UTF-16LE", $word)); + + my $hash = sprintf ("%s:%s", $digest, $salt); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my ($hash, $salt, $word) = split (':', $line); + + return unless defined $hash; + return unless defined $salt; + return unless defined $word; + + $word = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word, $salt); + + return $new_hash; +} + +1;