159 lines
5 KiB
C
159 lines
5 KiB
C
#ifndef ENCRYPTION_UTILITY_H
|
|
#define ENCRYPTION_UTILITY_H
|
|
|
|
// header files
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "File_Input_Utility.h"
|
|
#include "File_Output_Utility.h"
|
|
#include "Console_IO_Utility.h"
|
|
#include "StandardConstants.h"
|
|
|
|
// global constants
|
|
|
|
// data structures
|
|
|
|
typedef enum { DISPLAY_CHARS = 101, DISPLAY_INTS } ControlCode;
|
|
|
|
typedef struct SquareArrayStruct
|
|
{
|
|
int **array;
|
|
|
|
int sideSize;
|
|
} SquareArrayType;
|
|
|
|
// 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 );
|
|
|
|
/*
|
|
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 );
|
|
|
|
/*
|
|
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 );
|
|
|
|
/*
|
|
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 );
|
|
/*
|
|
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 );
|
|
|
|
/*
|
|
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 );
|
|
|
|
/*
|
|
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 );
|
|
/*
|
|
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 );
|
|
|
|
/*
|
|
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();
|
|
/*
|
|
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 );
|
|
|
|
|
|
|
|
#endif // ENCRYPTION_UTILITY_H
|