Release Ready!
+- Makefile for compiling +- EncryptionUtility.c (80 char limits) ++ outRelease (precompiled program for UNIX systems)
This commit is contained in:
parent
c1db9f52b8
commit
c7bcb36a76
4 changed files with 58 additions and 41 deletions
|
|
@ -21,11 +21,11 @@ Dependencies: as needed
|
||||||
*/
|
*/
|
||||||
SquareArrayType *clearArrayType( SquareArrayType *data )
|
SquareArrayType *clearArrayType( SquareArrayType *data )
|
||||||
{
|
{
|
||||||
int oneDimensionIndex;
|
int rowIndex;
|
||||||
|
|
||||||
for( oneDimensionIndex = 0; oneDimensionIndex < data->sideSize; oneDimensionIndex++ )
|
for( rowIndex = 0; rowIndex < data->sideSize; rowIndex++ )
|
||||||
{
|
{
|
||||||
free( data->array[ oneDimensionIndex ] );
|
free( data->array[ rowIndex ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
free( data->array );
|
free( data->array );
|
||||||
|
|
@ -50,7 +50,7 @@ Dependencies: as needed
|
||||||
*/
|
*/
|
||||||
SquareArrayType *createArrayType( int sideSize )
|
SquareArrayType *createArrayType( int sideSize )
|
||||||
{
|
{
|
||||||
int oneDimensionIndex, twoDimensionIndex;
|
int rowIndex, colIndex;
|
||||||
SquareArrayType *newData;
|
SquareArrayType *newData;
|
||||||
|
|
||||||
newData = (SquareArrayType *)malloc( sizeof( SquareArrayType ) );
|
newData = (SquareArrayType *)malloc( sizeof( SquareArrayType ) );
|
||||||
|
|
@ -59,13 +59,13 @@ SquareArrayType *createArrayType( int sideSize )
|
||||||
|
|
||||||
newData->array = (int **)malloc( sideSize * sizeof( int * ) );
|
newData->array = (int **)malloc( sideSize * sizeof( int * ) );
|
||||||
|
|
||||||
for( oneDimensionIndex = 0; oneDimensionIndex < sideSize; oneDimensionIndex++ )
|
for( rowIndex = 0; rowIndex < sideSize; rowIndex++ )
|
||||||
{
|
{
|
||||||
newData->array[ oneDimensionIndex ] = (int *)malloc( sideSize * sizeof( int ) );
|
newData->array[ rowIndex ] = (int *)malloc( sideSize * sizeof( int ) );
|
||||||
|
|
||||||
for( twoDimensionIndex = 0; twoDimensionIndex < sideSize; twoDimensionIndex++ )
|
for( colIndex = 0; colIndex < sideSize; colIndex++ )
|
||||||
{
|
{
|
||||||
newData->array[ oneDimensionIndex ][ twoDimensionIndex ] = (int)ASTERISK;
|
newData->array[ rowIndex ][ colIndex ] = (int)ASTERISK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,20 +93,22 @@ void decryptData( char *decryptStr, SquareArrayType *data )
|
||||||
int differenceIndex;
|
int differenceIndex;
|
||||||
int currentCharacter = 0;
|
int currentCharacter = 0;
|
||||||
int stringComplete = 0;
|
int stringComplete = 0;
|
||||||
for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0; oneDimensionIndex--)
|
for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0;
|
||||||
|
oneDimensionIndex--)
|
||||||
{
|
{
|
||||||
// does one dimensional indices
|
// does one dimensional indices
|
||||||
for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--)
|
for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0;
|
||||||
|
twoDimensionIndex--)
|
||||||
{
|
{
|
||||||
// does two dimensional indices
|
// does two dimensional indices
|
||||||
differenceIndex = oneDimensionIndex - twoDimensionIndex;
|
differenceIndex = oneDimensionIndex - twoDimensionIndex;
|
||||||
if(differenceIndex < arraySizeData && twoDimensionIndex < arraySizeData)
|
if(differenceIndex < arraySizeData && twoDimensionIndex < arraySizeData)
|
||||||
{
|
{
|
||||||
// printf("C ");
|
|
||||||
// second dimension to move through array
|
// second dimension to move through array
|
||||||
if(stringComplete == 0)
|
if(stringComplete == 0)
|
||||||
{
|
{
|
||||||
if(data->array[twoDimensionIndex][differenceIndex] == UNPRINTABLE_CHAR_VALUE)
|
if(data->array[twoDimensionIndex][differenceIndex] ==
|
||||||
|
UNPRINTABLE_CHAR_VALUE)
|
||||||
{
|
{
|
||||||
// check for the unprintable character
|
// check for the unprintable character
|
||||||
decryptStr[currentCharacter] = NULL_CHAR;
|
decryptStr[currentCharacter] = NULL_CHAR;
|
||||||
|
|
@ -115,13 +117,13 @@ void decryptData( char *decryptStr, SquareArrayType *data )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// put the character into the string.
|
// put the character into the string.
|
||||||
decryptStr[currentCharacter] = data->array[twoDimensionIndex][differenceIndex];
|
decryptStr[currentCharacter] =
|
||||||
|
data->array[twoDimensionIndex][differenceIndex];
|
||||||
currentCharacter = currentCharacter + 1;
|
currentCharacter = currentCharacter + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("\n");
|
|
||||||
}
|
}
|
||||||
// no return.
|
// no return.
|
||||||
}
|
}
|
||||||
|
|
@ -144,12 +146,15 @@ void displayArray( const SquareArrayType data, ControlCode ctrlCode )
|
||||||
int oneDimensionIndex = 0, twoDimensionIndex = 0;
|
int oneDimensionIndex = 0, twoDimensionIndex = 0;
|
||||||
// check the control code, branch to the respective path.
|
// check the control code, branch to the respective path.
|
||||||
// iterate through the array, one character at a time.
|
// iterate through the array, one character at a time.
|
||||||
// get the side size from the array, iterate that number of times, then output a new line.
|
// get the side size from the array,
|
||||||
|
// iterate that number of times, then output a new line.
|
||||||
if(ctrlCode == DISPLAY_CHARS)
|
if(ctrlCode == DISPLAY_CHARS)
|
||||||
{
|
{
|
||||||
for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++)
|
for(oneDimensionIndex = 0; oneDimensionIndex < arraySize;
|
||||||
|
oneDimensionIndex++)
|
||||||
{
|
{
|
||||||
for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++)
|
for(twoDimensionIndex = 0; twoDimensionIndex < arraySize;
|
||||||
|
twoDimensionIndex++)
|
||||||
{
|
{
|
||||||
printCharacter((char)data.array[oneDimensionIndex][twoDimensionIndex]);
|
printCharacter((char)data.array[oneDimensionIndex][twoDimensionIndex]);
|
||||||
printCharacter(SPACE);
|
printCharacter(SPACE);
|
||||||
|
|
@ -159,9 +164,11 @@ void displayArray( const SquareArrayType data, ControlCode ctrlCode )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++)
|
for(oneDimensionIndex = 0; oneDimensionIndex < arraySize;
|
||||||
|
oneDimensionIndex++)
|
||||||
{
|
{
|
||||||
for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++)
|
for(twoDimensionIndex = 0; twoDimensionIndex < arraySize;
|
||||||
|
twoDimensionIndex++)
|
||||||
{
|
{
|
||||||
printInteger((int)data.array[oneDimensionIndex][twoDimensionIndex]);
|
printInteger((int)data.array[oneDimensionIndex][twoDimensionIndex]);
|
||||||
printCharacter(SPACE);
|
printCharacter(SPACE);
|
||||||
|
|
@ -199,10 +206,12 @@ void downloadData( const char *fileName, const SquareArrayType data )
|
||||||
// write a new line
|
// write a new line
|
||||||
writeEndlineToFile();
|
writeEndlineToFile();
|
||||||
// iterate through array outputting each integer.
|
// iterate through array outputting each integer.
|
||||||
for(oneDimensionIndex = 0; oneDimensionIndex < data.sideSize; oneDimensionIndex++)
|
for(oneDimensionIndex = 0; oneDimensionIndex < data.sideSize;
|
||||||
|
oneDimensionIndex++)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
for(twoDimensionIndex = 0; twoDimensionIndex < data.sideSize; twoDimensionIndex++)
|
for(twoDimensionIndex = 0; twoDimensionIndex < data.sideSize;
|
||||||
|
twoDimensionIndex++)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
currentData = data.array[oneDimensionIndex][twoDimensionIndex];
|
currentData = data.array[oneDimensionIndex][twoDimensionIndex];
|
||||||
|
|
@ -250,49 +259,55 @@ SquareArrayType *encryptData( const char *toEncrypt )
|
||||||
{
|
{
|
||||||
// get length of string (store in variable)
|
// get length of string (store in variable)
|
||||||
int stringLen = findStringLength(toEncrypt);
|
int stringLen = findStringLength(toEncrypt);
|
||||||
// create the array (get the square root, add one, then call the function to make a square array.)
|
// create the array (get the square root, add one,
|
||||||
|
// then call the function to make a square array.)
|
||||||
int stringLenRoot = findSquareRoot(stringLen) + 1;
|
int stringLenRoot = findSquareRoot(stringLen) + 1;
|
||||||
SquareArrayType *encryptedData = createArrayType(stringLenRoot);
|
SquareArrayType *encryptedData = createArrayType(stringLenRoot);
|
||||||
// iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array]
|
// iterate through the array (backwards, diagonally)
|
||||||
int oneDimensionIndex;
|
int oneDimensionIndex;
|
||||||
int twoDimensionIndex;
|
int twoDimensionIndex;
|
||||||
int differenceIndex;
|
int differenceIndex;
|
||||||
int currentCharacter = 0;
|
int currentCharacter = 0;
|
||||||
for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--)
|
for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0;
|
||||||
|
oneDimensionIndex--)
|
||||||
{
|
{
|
||||||
// does one dimensional indices
|
// does one dimensional indices
|
||||||
for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--)
|
for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0;
|
||||||
|
twoDimensionIndex--)
|
||||||
{
|
{
|
||||||
// does two dimensional indices
|
// does two dimensional indices
|
||||||
differenceIndex = oneDimensionIndex - twoDimensionIndex;
|
differenceIndex = oneDimensionIndex - twoDimensionIndex;
|
||||||
if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot)
|
if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot)
|
||||||
{
|
{
|
||||||
// printf("C ");
|
|
||||||
// second dimension to move through array
|
// second dimension to move through array
|
||||||
if(currentCharacter >= stringLen)
|
if(currentCharacter >= stringLen)
|
||||||
{
|
{
|
||||||
if(currentCharacter == stringLen)
|
if(currentCharacter == stringLen)
|
||||||
{
|
{
|
||||||
// if the null character is there, replace with the Unprintable, set flag to one.
|
// if the null character is there,
|
||||||
encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE;
|
// replace with the Unprintable, set flag to one.
|
||||||
|
encryptedData->array[twoDimensionIndex][differenceIndex] =
|
||||||
|
UNPRINTABLE_CHAR_VALUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if not the null, put random data into array
|
// if not the null, put random data into array
|
||||||
encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue();
|
encryptedData->array[twoDimensionIndex][differenceIndex] =
|
||||||
|
getRandomLetterValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// otherwise, continue putting the data into the 2d array.
|
// otherwise, continue putting the data into the 2d array.
|
||||||
encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter];
|
encryptedData->array[twoDimensionIndex][differenceIndex] =
|
||||||
|
toEncrypt[currentCharacter];
|
||||||
}
|
}
|
||||||
currentCharacter = currentCharacter + 1;
|
currentCharacter = currentCharacter + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//printf("\n");
|
|
||||||
}
|
}
|
||||||
// once null character is reached, put the 'unprintable character' then random data afterward.
|
// once null character is reached, put the 'unprintable character'
|
||||||
|
// then random data afterward.
|
||||||
// returns a Square Array.
|
// returns a Square Array.
|
||||||
return encryptedData;
|
return encryptedData;
|
||||||
}
|
}
|
||||||
|
|
@ -425,13 +440,15 @@ SquareArrayType *uploadData( const char *fileName )
|
||||||
// create the square array
|
// create the square array
|
||||||
readArray = createArrayType(arraySizeFile);
|
readArray = createArrayType(arraySizeFile);
|
||||||
// read integer, iterate through array inputting each integer.
|
// read integer, iterate through array inputting each integer.
|
||||||
for(oneDimensionIndex = 0; oneDimensionIndex < arraySizeFile; oneDimensionIndex++)
|
for(oneDimensionIndex = 0; oneDimensionIndex < arraySizeFile;
|
||||||
|
oneDimensionIndex++)
|
||||||
{
|
{
|
||||||
//
|
for(twoDimensionIndex = 0; twoDimensionIndex < arraySizeFile;
|
||||||
for(twoDimensionIndex = 0; twoDimensionIndex < arraySizeFile; twoDimensionIndex++)
|
twoDimensionIndex++)
|
||||||
{
|
{
|
||||||
//
|
// input data into array from file
|
||||||
readArray->array[oneDimensionIndex][twoDimensionIndex] = readIntegerFromFile();
|
readArray->array[oneDimensionIndex][twoDimensionIndex] =
|
||||||
|
readIntegerFromFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@ CC = gcc -Wall
|
||||||
SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
||||||
OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
||||||
|
|
||||||
all: PA01_Main.out
|
all: PA01_Main
|
||||||
|
|
||||||
PA01_Main.out: PA01_Main
|
|
||||||
./PA01_Main | tee PA01_Main.out
|
|
||||||
|
|
||||||
PA01_Main: $(OBJECTS)
|
PA01_Main: $(OBJECTS)
|
||||||
$(CC) $(OBJECTS) -o PA01_Main
|
$(CC) $(OBJECTS) -o PA01_Main
|
||||||
|
|
@ -30,3 +27,6 @@ clean:
|
||||||
|
|
||||||
clean_objects:
|
clean_objects:
|
||||||
rm -f $(OBJECTS)
|
rm -f $(OBJECTS)
|
||||||
|
|
||||||
|
run:
|
||||||
|
./PA01_Main
|
||||||
Binary file not shown.
BIN
PA01-0906/build/Release/outRelease
Executable file
BIN
PA01-0906/build/Release/outRelease
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue