//----------------------------------------------------------------------------
//
//  ise_test_18.cpp
//
//  Authors: Joe Jarchow, Geoffrey Griffith, Joseph Kadhim, Shinya Daigaku
//           Andrew Pouzeshi
//
//  Sponsor: Tom Lookabaugh, Assistant Professor of Computer Science
//           University of Colorado
//
//  Senior Project: Team ISE (Image Selective Encryption)
//----------------------------------------------------------------------------


// This file is designed to test the ISE production code with test18.sh

#include <stdlib.h>     
#include <iostream>
#include <fstream> 
#include <string>
#include "rijndael-api-fst.h"
#include "ise.h"

using namespace std;

int main(int argc, char * argv[])
{
    /* Dencrypt_File Function Normal Use */
    size_t length = 0;
    int err = 0;
    char * MyKey;
    char * MyISE;
    char * NewJpeg;	

    // Set the key
    if (argc > 0)
    {
        length = strlen(argv[1]);
        MyKey = new char [length + 1];
        strcpy (MyKey,argv[1]);
    }
    else
    {
        length = strlen("Bad_Key");
        MyKey = new char [length + 1];
        strcpy (MyKey,"Bad_Key");
    }

    // Set ISE file name
    if (argc > 1)
    {
        length = strlen(argv[2]);
        MyISE = new char [length + 1];
        strcpy (MyISE,argv[2]);
    }
    else
    {
        length = strlen("images/ralphie.jpg");
        MyISE = new char [length + 1];
        strcpy (MyISE,"images/ralphie.jpg");
    }

    // Set new jpeg file name
    if (argc > 2)
    {
        length = strlen(argv[3]);
        NewJpeg = new char [length + 1];
        strcpy (NewJpeg,argv[3]);
    }
    else
    {
      length = strlen("images/ralphie.ise");
      NewJpeg = new char [length + 1];
      strcpy (NewJpeg, "images/ralphie.ise");
    }

    /* Call the constructor with key, jpeg file, and ise file */
    jpeg_ise decrypt_test(MyKey, MyISE, NewJpeg);

    /* Dencryption */
    err = decrypt_test.decrypt_file();
    if (err != 0) 
    {
      cout << "Test 18: Decryption failed on file: " << MyISE << " with error " << err << endl;
    }
	
    delete [] MyKey;
    delete [] MyISE;
    delete [] NewJpeg;

    return 0;
}
