Uploading Changes

+- EncryptionUtility.c
+- PA01_Main
This commit is contained in:
Charles Descamps 2023-09-04 13:52:30 -07:00
parent 40e0bfd79a
commit 4b87557bcf
3 changed files with 55 additions and 26 deletions

View file

@ -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;
}
/*

Binary file not shown.

View file

@ -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,7 +43,7 @@ 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 );