1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  
     | 
    
      #!/usr/bin/perl
# Adapted from http://gist.github.com/212780
use strict;
use warnings;
use Test::More tests => 7;
use Digest::Whirlpool;
#use Digest::MD5;
my @digesters;
for ( 1..5 ){
  push @digesters, {
      whirlpool => Digest::Whirlpool->new(),
      #md5 => Digest::MD5->new()
  };
}
# seeing that its constant accross instances.
for ( @digesters ) {
  my $hex = $_->{whirlpool}->hexdigest();
  my $hexd = $_->{whirlpool}->hexdigest();
  is($hex, $hexd, "Whirlpool: Two digest with no input added are the same");
  #$hex = $_->{md5}->hexdigest();
  #$hexd = $_->{md5}->hexdigest();
  #is($hex, $hexd, "MD5: Two digest with no input added are the same");
}
sub some_key
{
    my $hash = shift;
    if (my @keys = keys %$hash) {
        return $keys[0];
    }
    return;
}
my $tests = 1000;
# seeing that within a single digester, the same empty value results in a pseudorandom sequence generation.
{
    my (%whirl, %md5);
    $digesters[0]->{whirlpool}->reset();
    #$digesters[0]->{md5}->reset();
    for ( 1..$tests ) {
        my $digest = $digesters[0]->{whirlpool}->hexdigest;
        $whirl{$digest} = 1;
    }
    is_deeply({ some_key(\%whirl) => 1 }, \%whirl, "Whirlpool: Should only have one digest");
    #for ( 1..$tests ){
    #    my $digest = $digesters[0]->{md5}->hexdigest;
    #    $md5{ $digest } = 1;
    #}
    #is_deeply({ some_key(\%md5) => 1 }, \%md5, "MD5: Should only have one digest");
}
# seeing that the digester doesn't conform to the specification that the rest conform to
# with regard to hexdigest resetting the state.
{
    my (%whirl, %md5);
    $digesters[0]->{whirlpool}->reset();
    #$digesters[0]->{md5}->reset();
    for ( 1..$tests ) {
        $digesters[0]->{whirlpool}->add('hello');
        my $digest = $digesters[0]->{whirlpool}->hexdigest;
        $whirl{$digest} = 1;
    }
    is_deeply({ some_key(\%whirl) => 1 }, \%whirl, "Whirlpool: Should only have one digest");
    #for ( 1..$tests ){
    #    $digesters[0]->{md5}->add('hello');
    #    my $digest = $digesters[0]->{md5}->hexdigest;
    #    $md5{ $digest } = 1;
    #}
    #is_deeply({ some_key(\%md5) => 1 }, \%md5, "MD5: Should only have one digest");
}
 
     |