diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 253cfc0..5b5bfef 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -21,11 +21,11 @@ Dependencies: as needed */ 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 ); @@ -50,7 +50,7 @@ Dependencies: as needed */ SquareArrayType *createArrayType( int sideSize ) { - int oneDimensionIndex, twoDimensionIndex; + int rowIndex, colIndex; SquareArrayType *newData; newData = (SquareArrayType *)malloc( sizeof( SquareArrayType ) ); @@ -59,13 +59,13 @@ SquareArrayType *createArrayType( int sideSize ) 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 currentCharacter = 0; int stringComplete = 0; - for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0; oneDimensionIndex--) + for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0; + oneDimensionIndex--) { // does one dimensional indices - for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; + twoDimensionIndex--) { // does two dimensional indices differenceIndex = oneDimensionIndex - twoDimensionIndex; if(differenceIndex < arraySizeData && twoDimensionIndex < arraySizeData) { - // printf("C "); // second dimension to move through array if(stringComplete == 0) { - if(data->array[twoDimensionIndex][differenceIndex] == UNPRINTABLE_CHAR_VALUE) + if(data->array[twoDimensionIndex][differenceIndex] == + UNPRINTABLE_CHAR_VALUE) { // check for the unprintable character decryptStr[currentCharacter] = NULL_CHAR; @@ -115,13 +117,13 @@ void decryptData( char *decryptStr, SquareArrayType *data ) else { // put the character into the string. - decryptStr[currentCharacter] = data->array[twoDimensionIndex][differenceIndex]; + decryptStr[currentCharacter] = + data->array[twoDimensionIndex][differenceIndex]; currentCharacter = currentCharacter + 1; } } } } - // printf("\n"); } // no return. } @@ -144,12 +146,15 @@ void displayArray( const SquareArrayType data, ControlCode ctrlCode ) int oneDimensionIndex = 0, twoDimensionIndex = 0; // check the control code, branch to the respective path. // 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) { - 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(SPACE); @@ -159,9 +164,11 @@ void displayArray( const SquareArrayType data, ControlCode ctrlCode ) } 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]); printCharacter(SPACE); @@ -199,10 +206,12 @@ void downloadData( const char *fileName, const SquareArrayType data ) // write a new line writeEndlineToFile(); // 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]; @@ -250,49 +259,55 @@ SquareArrayType *encryptData( const char *toEncrypt ) { // get length of string (store in variable) 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; 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 twoDimensionIndex; int differenceIndex; int currentCharacter = 0; - for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--) + for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; + oneDimensionIndex--) { // does one dimensional indices - for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; + twoDimensionIndex--) { // does two dimensional indices differenceIndex = oneDimensionIndex - twoDimensionIndex; if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot) { - // printf("C "); // second dimension to move through array if(currentCharacter >= stringLen) { if(currentCharacter == stringLen) { - // if the null character is there, replace with the Unprintable, set flag to one. - encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE; + // if the null character is there, + // replace with the Unprintable, set flag to one. + encryptedData->array[twoDimensionIndex][differenceIndex] = + UNPRINTABLE_CHAR_VALUE; } else { // if not the null, put random data into array - encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue(); + encryptedData->array[twoDimensionIndex][differenceIndex] = + getRandomLetterValue(); } } else { // otherwise, continue putting the data into the 2d array. - encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter]; + encryptedData->array[twoDimensionIndex][differenceIndex] = + toEncrypt[currentCharacter]; } 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. return encryptedData; } @@ -425,13 +440,15 @@ SquareArrayType *uploadData( const char *fileName ) // create the square array readArray = createArrayType(arraySizeFile); // 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; twoDimensionIndex++) + for(twoDimensionIndex = 0; twoDimensionIndex < arraySizeFile; + twoDimensionIndex++) { - // - readArray->array[oneDimensionIndex][twoDimensionIndex] = readIntegerFromFile(); + // input data into array from file + readArray->array[oneDimensionIndex][twoDimensionIndex] = + readIntegerFromFile(); } } } diff --git a/PA01-0906/Makefile b/PA01-0906/Makefile index 654ac86..b806f02 100644 --- a/PA01-0906/Makefile +++ b/PA01-0906/Makefile @@ -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 OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o -all: PA01_Main.out - -PA01_Main.out: PA01_Main - ./PA01_Main | tee PA01_Main.out +all: PA01_Main PA01_Main: $(OBJECTS) $(CC) $(OBJECTS) -o PA01_Main @@ -30,3 +27,6 @@ clean: clean_objects: rm -f $(OBJECTS) + +run: + ./PA01_Main \ No newline at end of file diff --git a/PA01-0906/PA01_Main b/PA01-0906/PA01_Main index 70ca7c0..73d212a 100755 Binary files a/PA01-0906/PA01_Main and b/PA01-0906/PA01_Main differ diff --git a/PA01-0906/build/Release/outRelease b/PA01-0906/build/Release/outRelease new file mode 100755 index 0000000..5ef0f69 Binary files /dev/null and b/PA01-0906/build/Release/outRelease differ