1#!/usr/bin/env perl 2 3## 4## Author......: See docs/credits.txt 5## License.....: MIT 6## 7 8use strict; 9use warnings; 10use MIME::Base64 qw (encode_base64 decode_base64); 11 12use Digest::MD5 qw (md5); 13 14sub module_constraints { [[-1, -1], [-1, -1], [0, 55], [-1, -1], [-1, -1]] } 15 16my $itoa62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 17 18sub module_generate_hash 19{ 20 my $word = shift; 21 22 my $digest = md5 ($word); 23 24 my @chksum; 25 26 for (my $i = 0, my $j = 0; $i < 16; $i += 2, $j += 1) 27 { 28 $chksum[$j] = (ord (substr ($digest, $i + 0, 1)) + ord (substr ($digest, $i + 1, 1))) % 62; 29 30 $chksum[$j] = substr ($itoa62, $chksum[$j], 1); 31 } 32 33 my $res = join "", @chksum; 34 35 my $hash = sprintf ("%s", $res); 36 37 return $hash; 38} 39 40sub module_verify_hash 41{ 42 my $line = shift; 43 44 my ($hash, $word) = split (':', $line); 45 46 return unless defined $hash; 47 return unless defined $word; 48 49 my $word_packed = pack_if_HEX_notation ($word); 50 51 my $new_hash = module_generate_hash ($word_packed); 52 53 return ($new_hash, $word); 54} 55 561; 57