1#!/usr/bin/env perl
2
3##
4## Author......: See docs/credits.txt
5## License.....: MIT
6##
7
8use strict;
9use warnings;
10
11use Digest::SHA qw (sha1_hex);
12
13sub module_constraints { [[0, 256], [8, 8], [0, 54], [8, 8], [8, 54]] }
14
15sub module_generate_hash
16{
17  my $word = shift;
18  my $salt = shift;
19
20  my $hash_buf = sha1_hex ($salt . $word . "\x00");
21
22  my $hash = sprintf ("1%s%s", $salt, $hash_buf);
23
24  return $hash;
25}
26
27sub module_verify_hash
28{
29  my $line = shift;
30
31  my $salt = substr ($line, 1, 8);
32
33  my $rest = substr ($line, 1 + 8);
34
35  my $index2 = index ($rest, ":");
36
37  return if $index2 < 1;
38
39  my $word = substr ($rest, $index2 + 1);
40
41  return unless defined $salt;
42  return unless defined $word;
43
44  $word = pack_if_HEX_notation ($word);
45
46  my $new_hash = module_generate_hash ($word, $salt);
47
48  return ($new_hash, $word);
49}
50
511;
52