RSA_test_script
contents ::
  App.java
  plaintext_1
  plaintext_2
  plaintext_3
  plaintext_4
  plaintext_5
  RSA_test_script

#!/bin/bash
#
# File: RSA_test_script
# Script for exercise 10 on multiple files
# Iain Hewson May 2001

TEMPDIR="tempDir"

mkdir ${TEMPDIR}

# if there is already a directory called tempDir - exit so we don't delete it
if [ $? -ne 0 ]; then
    echo "Error couldn't make new directory ${TEMPDIR}"
    exit -1
fi

# make program
make

echo -e "\nGenerating encrypted files\n--------------------------"

# for each plaintext file produce an encrypted file with the same suffix
for i in `ls plaintext_*`
do
    echo "Reading $i / writing encrypted${i#plaintext}"
    make run < $i > ${TEMPDIR}/encrypted${i#plaintext}
done

echo -e "\nGenerating decrypted files\n--------------------------"

# for each ciphertext file produce a decrypted file with the same suffix
for i in `ls ciphertext_*`
do
    echo "Reading $i / writing decrypted${i#ciphertext}"
    make run < $i > ${TEMPDIR}/decrypted${i#ciphertext}
done


echo -e "\nComparing encrypted files\n-------------------------"

# compare each ciphertext file to the corresponding encrypted file
for i in `ls ciphertext_*`
do
    head -n 3 $i > ${TEMPDIR}/just_a_temp_file
    cat ${TEMPDIR}/encrypted${i#ciphertext} >> ${TEMPDIR}/just_a_temp_file
    diff ${TEMPDIR}/just_a_temp_file $i > /dev/null
    if [ $? -eq 0 ]; then
         echo Encryption of plaintext${i#ciphertext} matches $i
    else
         echo Encryption of plaintext${i#ciphertext} DOES NOT match $i
    fi
done


echo -e "\nComparing decrypted files\n-------------------------"

# compare each plaintext file to the corresponding decrypted file
for i in `ls plaintext_*`
do
    head -n 3 $i > ${TEMPDIR}/just_a_temp_file
    cat ${TEMPDIR}/decrypted${i#plaintext} >> ${TEMPDIR}/just_a_temp_file
    diff ${TEMPDIR}/just_a_temp_file $i > /dev/null
    if [ $? -eq 0 ]; then
         echo Decryption of ciphertext${i#plaintext} matches $i
    else
         echo Decryption of ciphertext${i#plaintext} DOES NOT match $i
    fi
done

rm -rf ${TEMPDIR} # clean up

exit 0

James Little