#!/bin/bash

# The shell script to execute RSA with different values of
# The Key Size (from 128 to 1024 bits)
# The message len (from 1 to 4096)
# The Certainty factor in finding the prime nos. (from 10 to 50)

# The factors that are taken constant are(when other are varied)
# Message Length : 100
# KeySize : 256
# Probability constant : 10

FileStatKey="Statistics.file"
ProbConstt=10
MsgConstt=100
KeyConstt=256
MessageFile="Message.txt"
DummyFile="Dummy"
makemessagefile()
{
	char=1
	i=1
	len=$1
	cat $DummyFile > $MessageFile
	while test $i -lt $len
	do
		case $char in
		[!0-9]	) char=0;;
		esac
	
		# echo $char >> $MessageFile
		cat $DummyFile >> $MessageFile
		char=`expr $char + 1`
		i=`expr $i + 1`
	done
	
	echo -e "\n" >> $MessageFile	
	return 0
}


key()
{
	keysize=128
	limit=1024
	factor=2

	makemessagefile $MsgConstt
	while test $keysize -le $limit
	do
		echo -e "\n\nVariation in Keysizes\n" >> $FileStatKey
		java EncryptRSA $keysize $ProbConstt >> $FileStatKey
		keysize=`expr $keysize \* $factor`
	done

}

msg()
{
        msgsize=2
        limit=4096
        factor=2

        while test $msgsize -le $limit
        do
                echo -e "\n\nVariation in Msgsizes\n" >> $FileStatKey
		makemessagefile $msgsize
                java EncryptRSA $KeyConstt $ProbConstt >> $FileStatKey
                msgsize=`expr $msgsize \* $factor`
        done

}


prob()
{
        probsize=2
        limit=64
        factor=2

	makemessagefile $MsgConstt
        while test $probsize -le $limit
        do
                echo -e "\n\nVariation in prob. value\n" >> $FileStatKey
                java EncryptRSA $KeyConstt $probsize >> $FileStatKey
                probsize=`expr $probsize \* $factor`
        done

}


		




# Usage  : $ExecuteRSA.sh <key|msg|prob>

if test $# -ne 1
then
	echo "Usage : `basename $0` <key|msg|prob>"
	exit 0
fi


case $1 in
key	) key;
	  exit 0;;
msg	) msg;
	  exit 0;;
prob	) prob;
	  exit 0;;	
*	)	
	echo "Usage : `basename $0` <key|msg|prob>";
	exit 0;;
esac


	
