diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 74ff263..8d5281a 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -101,6 +101,35 @@ Notes: Does not handle empty square data type condition */ void displayArray( const SquareArrayType data, ControlCode ctrlCode ) { + int arraySize = data.sideSize; + 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. + if(ctrlCode == DISPLAY_CHARS) + { + for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++) + { + for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++) + { + printCharacter((char)data.array[oneDimensionIndex][twoDimensionIndex]); + printCharacter(SPACE); + } + printEndline(); + } + } + else + { + for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++) + { + for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++) + { + printInteger((int)data.array[oneDimensionIndex][twoDimensionIndex]); + printCharacter(SPACE); + } + printEndline(); + } + } // no return. } /* @@ -148,33 +177,34 @@ SquareArrayType *encryptData( const char *toEncrypt ) int twoDimensionIndex; int currentCharacter = 0; int flagEndString = 0; - for(oneDimensionIndex = stringLenRoot; oneDimensionIndex >= 0; oneDimensionIndex--) + for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--) { // one dimension to move through array - for(twoDimensionIndex = stringLenRoot; twoDimensionIndex >= 0; twoDimensionIndex--) + for(twoDimensionIndex = stringLenRoot - 1; twoDimensionIndex >= 0; twoDimensionIndex--) { + if(flagEndString == 1) + { + // check the flag, if it is set, then start putting random data into rest of the array. + encryptedData->array[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); + } // second dimension to move through array if(toEncrypt[currentCharacter] == NULL_CHAR) { // if the null character is there, replace with the Unprintable, set flag to one. - encryptedData[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; + encryptedData->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; flagEndString = 1; } else { // otherwise, continue putting the data into the 2d array. - encryptedData[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; - } - if(flagEndString == 1) - { - // check the flag, if it is set, then start putting random data into rest of the array. - encryptedData[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); + encryptedData->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; } + currentCharacter = currentCharacter + 1; } } // once null character is reached, put the 'unprintable character' then random data afterward. // returns a Square Array. - return NULL; + return encryptedData; } /* diff --git a/PA01-0906/PA01_Main b/PA01-0906/PA01_Main index b130d3b..286b100 100755 Binary files a/PA01-0906/PA01_Main and b/PA01-0906/PA01_Main differ diff --git a/PA01-0906/PA01_Main.c b/PA01-0906/PA01_Main.c index eb937f3..7b33ebb 100644 --- a/PA01-0906/PA01_Main.c +++ b/PA01-0906/PA01_Main.c @@ -12,20 +12,19 @@ // program int main( int argc, char *args[] ) { - srand( time( NULL ) ); //temp - int charNum; - char* string = "MyStringLengthThing"; - charNum = findStringLength(string); - printf("String Length: %d\n", charNum); - int squaredPerfect = 100; - int sqRT = findSquareRoot(squaredPerfect); - printf("%d's Square Root: %d\n", squaredPerfect, sqRT); - int randOne, randTwo, randThree; - randOne = getRandomLetterValue(); - randTwo = getRandomLetterValue(); - randThree = getRandomLetterValue(); - printf("Char Test: %d/%c, %d/%c, %d/%c", randOne, (char)randOne, randTwo, (char)randTwo, randThree, (char)randThree); - /* + // int charNum; + // char* string = "MyStringLengthThing"; + // charNum = findStringLength(string); + // printf("String Length: %d\n", charNum); + // int squaredPerfect = 100; + // int sqRT = findSquareRoot(squaredPerfect); + // printf("%d's Square Root: %d\n", squaredPerfect, sqRT); + // int randOne, randTwo, randThree; + // randOne = getRandomLetterValue(); + // randTwo = getRandomLetterValue(); + // randThree = getRandomLetterValue(); + // printf("Char Test: %d/%c, %d/%c, %d/%c\n\n", randOne, (char)randOne, randTwo, (char)randTwo, randThree, (char)randThree); + char toEncrypt[ HUGE_STR_LEN ], decryptedStr[ HUGE_STR_LEN ]; char fileName[ STD_STR_LEN ], stringFromFile[ HUGE_STR_LEN ]; SquareArrayType *encryptedInput, *uploadedInput; @@ -44,10 +43,10 @@ int main( int argc, char *args[] ) printf( "\nDisplay encryption as characters:\n" ); displayArray( *encryptedInput, DISPLAY_CHARS ); - + /* printf( "\nDecrypting the input string\n" ); decryptData( decryptedStr, encryptedInput ); - + printf( "\nDecrypted string: %s\n", decryptedStr ); printf( "\nDownloading encryption\n" );