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 ) 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. // no return.
} }
/* /*
@ -148,33 +177,34 @@ SquareArrayType *encryptData( const char *toEncrypt )
int twoDimensionIndex; int twoDimensionIndex;
int currentCharacter = 0; int currentCharacter = 0;
int flagEndString = 0; int flagEndString = 0;
for(oneDimensionIndex = stringLenRoot; oneDimensionIndex >= 0; oneDimensionIndex--) for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--)
{ {
// one dimension to move through array // 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 // second dimension to move through array
if(toEncrypt[currentCharacter] == NULL_CHAR) if(toEncrypt[currentCharacter] == NULL_CHAR)
{ {
// if the null character is there, replace with the Unprintable, set flag to one. // 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; flagEndString = 1;
} }
else else
{ {
// otherwise, continue putting the data into the 2d array. // otherwise, continue putting the data into the 2d array.
encryptedData[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; encryptedData->array[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();
} }
currentCharacter = currentCharacter + 1;
} }
} }
// 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 NULL; return encryptedData;
} }
/* /*

Binary file not shown.

View file

@ -12,20 +12,19 @@
// program // program
int main( int argc, char *args[] ) int main( int argc, char *args[] )
{ {
srand( time( NULL ) ); //temp // int charNum;
int charNum; // char* string = "MyStringLengthThing";
char* string = "MyStringLengthThing"; // charNum = findStringLength(string);
charNum = findStringLength(string); // printf("String Length: %d\n", charNum);
printf("String Length: %d\n", charNum); // int squaredPerfect = 100;
int squaredPerfect = 100; // int sqRT = findSquareRoot(squaredPerfect);
int sqRT = findSquareRoot(squaredPerfect); // printf("%d's Square Root: %d\n", squaredPerfect, sqRT);
printf("%d's Square Root: %d\n", squaredPerfect, sqRT); // int randOne, randTwo, randThree;
int randOne, randTwo, randThree; // randOne = getRandomLetterValue();
randOne = getRandomLetterValue(); // randTwo = getRandomLetterValue();
randTwo = getRandomLetterValue(); // randThree = getRandomLetterValue();
randThree = getRandomLetterValue(); // printf("Char Test: %d/%c, %d/%c, %d/%c\n\n", randOne, (char)randOne, randTwo, (char)randTwo, randThree, (char)randThree);
printf("Char Test: %d/%c, %d/%c, %d/%c", randOne, (char)randOne, randTwo, (char)randTwo, randThree, (char)randThree);
/*
char toEncrypt[ HUGE_STR_LEN ], decryptedStr[ HUGE_STR_LEN ]; char toEncrypt[ HUGE_STR_LEN ], decryptedStr[ HUGE_STR_LEN ];
char fileName[ STD_STR_LEN ], stringFromFile[ HUGE_STR_LEN ]; char fileName[ STD_STR_LEN ], stringFromFile[ HUGE_STR_LEN ];
SquareArrayType *encryptedInput, *uploadedInput; SquareArrayType *encryptedInput, *uploadedInput;
@ -44,7 +43,7 @@ int main( int argc, char *args[] )
printf( "\nDisplay encryption as characters:\n" ); printf( "\nDisplay encryption as characters:\n" );
displayArray( *encryptedInput, DISPLAY_CHARS ); displayArray( *encryptedInput, DISPLAY_CHARS );
/*
printf( "\nDecrypting the input string\n" ); printf( "\nDecrypting the input string\n" );
decryptData( decryptedStr, encryptedInput ); decryptData( decryptedStr, encryptedInput );