#!/usr/bin/perl

# This is a script to create graph from the temporary result file obtained 
# from experiment for different key/message sizes
# Author: Shweta Agrawal
# Date: Aug 15, 2003

if ($#ARGV != 1)
	{
	    print "Usage: creategraph <result file> <graph file>";
		exit;
	}
$resultfile = $ARGV[0];
$graphfile = $ARGV[1];

#open result file for reading
open RESULTFILE, $resultfile or die "Error reading result file: $! \n";
@alllines = <RESULTFILE>;
#open graph file for writing
open GRAPHFILE, ">$graphfile" or die "Error opening graph file for writing: $! \n";
print GRAPHFILE "#size generation encryption decryption\n";  	

#Scan the result file for the generation, encryption/decryption time values
$i=0;
while ($i<=$#alllines)
	{
	if( $alllines[$i] =~ /^Size:\s*(\d+)/)
		{
		$size = $1;
		$i = $i + 1;
		}
	if( $alllines[$i] =~ /^Key\s*Generation\s*Time:\s*(\d+)/)
		{
		$generation = $1;
		$i = $i + 1;
		}
	if( $alllines[$i] =~ /^Encryption\s*Time:\s*(\d+)/)
		{
		$encryption = $1;
		$i = $i + 1;
		}
	if( $alllines[$i] =~ /^Decryption\s*Time:\s*(\d+)/)
		{
		$decryption = $1;
		$i = $i + 1;
		}
	#print the desired values to the graph file	
	print GRAPHFILE "$size $generation $encryption $decryption\n";  	
	}

