#! /usr/bin/perl -w

use strict;


## this is the first attempt, all messages need to be
## padded, this is the padding for the single longest 
## message.. I will keep it like this for the moment 
my $pad="8000000160050000000000000000000000000000";
my $num_bytes=172;

my $num_bits=$num_bytes*8;


my $num = 10;
#my $num = 1;
my @stim;
my @md;



print "Generating stimuli: ";
for my $i (1..$num){

  my $data=uc(random_data($num_bytes));
  push (@stim,$data.$pad);
  open (AA, "> aa.txt") or die "can not open aa.txt\n";

print AA <<"BUGU";
# IntermediateKAT1.txt
# Algorithm Name: ECHO
# Principal Submitter: Henri Gilbert

Len = $num_bits
Msg = $data
Level = 4
MD = ??
BUGU
  close (AA);
  system("./echo_ref aa");
  open (AB, "< aa_256.txt") or die "aa_256.txt does not exist, why ?\n";


  while (){
    next unless (/^MD = ([0-9A-F]+)/);
    push (@md,$1);
  }
  close(AB);
  #print "$md\n";
}
print "Writing stimuli echo_stimuli.asc\n";
open (E, "> echo_expresp.asc") or die "wierd, can not open echo_expresp.asc\n";
open (S, "> echo_stimuli.asc") or die "wierd, can not open echo_stimuli.asc\n";

for my $i (0..$num-1){
  print S "1 $stim[$i]";
  print S "\n" unless ($i == $num-1);
  print E "$md[$i]";
  print E "\n" unless ($i == $num-1);

}
close (S);
close (E);




sub random_data {

my $num_bits = ($#_ > -1) ? $_[0] : 16;

# will generate a 128 bit data, can be used as input vector or key 

my $retval ="";
  for (1..$num_bits) {
     $retval = $retval . unpack ('H*', pack ('C1',int(rand(256))));
  }

return $retval;

}

Generated on Fri Sep 24 10:39:12 CEST 2010
Home