207 lines
5.8 KiB
C
207 lines
5.8 KiB
C
#include "EncryptionUtility.h"
|
|
|
|
// local constants
|
|
const char ASTERISK = '*';
|
|
const int UNPRINTABLE_CHAR_VALUE = 127; // delete key, unprintable
|
|
const int NUM_ALPHABET_LETTERS = 52;
|
|
const double SQRT_PRECISION = 0.000001;
|
|
const char ALPHABET[] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
|
|
|
|
// functions
|
|
|
|
/*
|
|
Name: clearArrayType
|
|
Process: Clears data type array rows, then data type array, then data type
|
|
Function input/parameters: pointer to square array type (SquareArrayType *)
|
|
Function output/parameters: none
|
|
Function output/returned: NULL (SquareArrayType *)
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed
|
|
*/
|
|
SquareArrayType *clearArrayType( SquareArrayType *data )
|
|
{
|
|
int rowIndex;
|
|
|
|
for( rowIndex = 0; rowIndex < data->sideSize; rowIndex++ )
|
|
{
|
|
free( data->array[ rowIndex ] );
|
|
}
|
|
|
|
free( data->array );
|
|
|
|
free( data );
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
Name: createArrayType
|
|
Process: Creates square array type, creates side size array rows,
|
|
creates side size array columns,
|
|
sets each element to ASTERISK constant,
|
|
sets side size to parameter value
|
|
Function input/parameters: array side size (int)
|
|
Function output/parameters: none
|
|
Function output/returned: pointer to new square array type (SquareArrayType *)
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed
|
|
*/
|
|
SquareArrayType *createArrayType( int sideSize )
|
|
{
|
|
int rowIndex, colIndex;
|
|
SquareArrayType *newData;
|
|
|
|
newData = (SquareArrayType *)malloc( sizeof( SquareArrayType ) );
|
|
|
|
newData->sideSize = sideSize;
|
|
|
|
newData->array = (int **)malloc( sideSize * sizeof( int * ) );
|
|
|
|
for( rowIndex = 0; rowIndex < sideSize; rowIndex++ )
|
|
{
|
|
newData->array[ rowIndex ] = (int *)malloc( sideSize * sizeof( int ) );
|
|
|
|
for( colIndex = 0; colIndex < sideSize; colIndex++ )
|
|
{
|
|
newData->array[ rowIndex ][ colIndex ] = (int)ASTERISK;
|
|
}
|
|
}
|
|
|
|
return newData;
|
|
}
|
|
|
|
/*
|
|
Name: decryptData
|
|
Process: Decrypts given data array, provides result as string
|
|
Function input/parameters: pointer to square array type (SquareArrayType *)
|
|
Function output/parameters: decrypted string (char *)
|
|
Function output/returned: none
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed
|
|
*/
|
|
void decryptData( char *decryptStr, SquareArrayType *data )
|
|
{
|
|
// no return.
|
|
}
|
|
|
|
/*
|
|
Name: displayArray
|
|
Process: Displays 2 dimensional array data either as characters or integers
|
|
depending on control code
|
|
Function input/parameters: square data array (const SquareArrayType)
|
|
Function output/parameters: none
|
|
Function output/returned: none
|
|
Device input/---: none
|
|
Device output/monitor: data displayed as specified
|
|
Dependencies: as needed
|
|
Notes: Does not handle empty square data type condition
|
|
*/
|
|
void displayArray( const SquareArrayType data, ControlCode ctrlCode )
|
|
{
|
|
// no return.
|
|
}
|
|
/*
|
|
Name: downloadData
|
|
Process: downloads given data array along with side size header,
|
|
does not download empty array (i.e., if side size is zero)
|
|
Function input/parameters: file name (const char *),
|
|
square data array (const SquareArrayType)
|
|
Function output/parameters: none
|
|
Function output/returned: none
|
|
Device input/---: none
|
|
Device output/HD: data output to file as specified
|
|
Dependencies: as needed, File_Output_Utility tools
|
|
*/
|
|
void downloadData( const char *fileName, const SquareArrayType data )
|
|
{
|
|
// no return.
|
|
}
|
|
|
|
/*
|
|
Name: encryptData
|
|
Process: finds side size for given string,
|
|
creates new array type,
|
|
encrypts data to 2D array using provided strategy
|
|
Function input/parameters: string to be encrypted (const char *)
|
|
Function output/parameters: none
|
|
Function output/returned: pointer to new array type (SquareArrayType *)
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed, including findStringLength, findSquareRoot,
|
|
getRandomLetterValue (library utilities may not be used)
|
|
*/
|
|
SquareArrayType *encryptData( const char *toEncrypt )
|
|
{
|
|
// returns a Square Array.
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
Name: findSquareRoot
|
|
Process: finds estimated square root of integer value
|
|
to specified SQRT_PRECISION using divide and conquer strategy
|
|
Function input/parameters: value to be square rooted (int)
|
|
Function output/parameters: none
|
|
Function output/returned: estimated square root as specified (double)
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed (library utilities may not be used)
|
|
*/
|
|
double findSquareRoot( int value )
|
|
{
|
|
// returns a double.
|
|
return 0.0;
|
|
}
|
|
|
|
/*
|
|
Name: findStringLength
|
|
Process: finds length of given c-style string
|
|
Function input/parameters: string for finding length (const char *)
|
|
Function output/parameters: none
|
|
Function output/returned: length of string (int)
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed (library utilities may not be used)
|
|
*/
|
|
int findStringLength( const char *str )
|
|
{
|
|
// returns an integer.
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
Name: getRandomLetterValue
|
|
Process: generates integer value of randomly found upper or lower case letter
|
|
in ALPHABET array
|
|
Function input/parameters: none
|
|
Function output/parameters: none
|
|
Function output/returned: integer value of random letter, as specified (int)
|
|
Device input/---: none
|
|
Device output/---: none
|
|
Dependencies: as needed, including rand
|
|
*/
|
|
int getRandomLetterValue()
|
|
{
|
|
// returns an integer.
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
Name: uploadData
|
|
Process: creates square array type, uploads data from text file,
|
|
gets side size from header, then loads array values
|
|
Function input/parameters: file name (const char *)
|
|
Function output/parameters: none
|
|
Function output/returned: pointer to square array type (SquareArrayType *)
|
|
Device input/HD: data input from text file as specified
|
|
Device output/---: none
|
|
Dependencies: as needed, File_Input_Utility tools
|
|
*/
|
|
SquareArrayType *uploadData( const char *fileName )
|
|
{
|
|
// returns a Square Array.
|
|
return NULL;
|
|
}
|