Getting Closer to fixing this

+- EncryptionUtility.c
+- PA01_Main
This commit is contained in:
Charles Descamps 2023-09-04 16:51:25 -07:00
parent 4b87557bcf
commit dc1a4f1638
2 changed files with 52 additions and 18 deletions

View file

@ -21,11 +21,11 @@ Dependencies: as needed
*/ */
SquareArrayType *clearArrayType( SquareArrayType *data ) SquareArrayType *clearArrayType( SquareArrayType *data )
{ {
int rowIndex; int oneDimensionIndex;
for( rowIndex = 0; rowIndex < data->sideSize; rowIndex++ ) for( oneDimensionIndex = 0; oneDimensionIndex < data->sideSize; oneDimensionIndex++ )
{ {
free( data->array[ rowIndex ] ); free( data->array[ oneDimensionIndex ] );
} }
free( data->array ); free( data->array );
@ -50,7 +50,7 @@ Dependencies: as needed
*/ */
SquareArrayType *createArrayType( int sideSize ) SquareArrayType *createArrayType( int sideSize )
{ {
int rowIndex, colIndex; int oneDimensionIndex, twoDimensionIndex;
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( rowIndex = 0; rowIndex < sideSize; rowIndex++ ) for( oneDimensionIndex = 0; oneDimensionIndex < sideSize; oneDimensionIndex++ )
{ {
newData->array[ rowIndex ] = (int *)malloc( sideSize * sizeof( int ) ); newData->array[ oneDimensionIndex ] = (int *)malloc( sideSize * sizeof( int ) );
for( colIndex = 0; colIndex < sideSize; colIndex++ ) for( twoDimensionIndex = 0; twoDimensionIndex < sideSize; twoDimensionIndex++ )
{ {
newData->array[ rowIndex ][ colIndex ] = (int)ASTERISK; newData->array[ oneDimensionIndex ][ twoDimensionIndex ] = (int)ASTERISK;
} }
} }
@ -175,32 +175,66 @@ SquareArrayType *encryptData( const char *toEncrypt )
// iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array] // iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array]
int oneDimensionIndex; int oneDimensionIndex;
int twoDimensionIndex; int twoDimensionIndex;
int differenceIndex;
int currentCharacter = 0; int currentCharacter = 0;
int flagEndString = 0; int flagEndString = 0;
for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--) // for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--)
// {
// // one dimension to move through array
// 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->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE;
// flagEndString = 1;
// }
// else
// {
// // otherwise, continue putting the data into the 2d array.
// encryptedData->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter];
// }
// currentCharacter = currentCharacter + 1;
// }
// }
for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--)
{ {
// one dimension to move through array //
for(twoDimensionIndex = stringLenRoot - 1; twoDimensionIndex >= 0; twoDimensionIndex--) for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--)
{ {
if(flagEndString == 1) //
differenceIndex = oneDimensionIndex - twoDimensionIndex;
if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot)
{ {
// check the flag, if it is set, then start putting random data into rest of the array. // printf("C ");
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->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE;
currentCharacter = currentCharacter + 1;
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->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter];
}
if(flagEndString == 1)
{
// check the flag, if it is set, then start putting random data into rest of the array.
encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue();
} }
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.

Binary file not shown.