1#!/usr/bin/env perl
2
3##
4## Author......: See docs/credits.txt
5## License.....: MIT
6##
7
8use strict;
9use warnings;
10
11sub module_constraints { [[0, 256], [-1, -1], [0, 55], [-1, -1], [-1, -1]] }
12
13sub hashCode
14{
15  use integer;
16
17  my $word = shift;
18
19  my @chars = unpack ("C*", $word);
20
21  my $hash = 0;
22
23  while (my $c = shift @chars)
24  {
25    $hash = ($hash * 31) + $c;
26  }
27
28  return $hash & 0xffffffff;
29}
30
31sub module_generate_hash
32{
33  my $word = shift;
34
35  my $digest = hashCode ($word);
36
37  my $hash = sprintf ("%08x", $digest);
38
39  return $hash;
40}
41
42sub module_verify_hash
43{
44  my $line = shift;
45
46  my ($hash, $word) = split (':', $line);
47
48  return unless defined $hash;
49  return unless defined $word;
50
51  my $word_packed = pack_if_HEX_notation ($word);
52
53  my $new_hash = module_generate_hash ($word_packed);
54
55  return ($new_hash, $word);
56}
57
581;
59