Modified PA01 Files

+- EncryptionUtility.c
+- PA01_Main.c
This commit is contained in:
Charles Descamps 2023-09-03 14:45:51 -07:00
parent b80e8624c0
commit 40e0bfd79a
3 changed files with 110 additions and 6 deletions

View file

@ -117,6 +117,9 @@ Dependencies: as needed, File_Output_Utility tools
*/
void downloadData( const char *fileName, const SquareArrayType data )
{
// open file.
// write file.
// close file.
// no return.
}
@ -135,6 +138,41 @@ Dependencies: as needed, including findStringLength, findSquareRoot,
*/
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.)
int stringLenRoot = findSquareRoot(stringLen) + 1;
SquareArrayType *encryptedData = createArrayType(stringLenRoot);
// iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array]
int oneDimensionIndex;
int twoDimensionIndex;
int currentCharacter = 0;
int flagEndString = 0;
for(oneDimensionIndex = stringLenRoot; oneDimensionIndex >= 0; oneDimensionIndex--)
{
// one dimension to move through array
for(twoDimensionIndex = stringLenRoot; twoDimensionIndex >= 0; twoDimensionIndex--)
{
// 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;
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();
}
}
}
// once null character is reached, put the 'unprintable character' then random data afterward.
// returns a Square Array.
return NULL;
}
@ -152,8 +190,47 @@ Dependencies: as needed (library utilities may not be used)
*/
double findSquareRoot( int value )
{
// returns a double.
return 0.0;
// declare, define variables as needed
// set lower value to zero, upper value to the original value
double lowerValue = 0, upperValue = value;
// set middle value between the lower and upper values
double middleValue = ( lowerValue + upperValue ) / 2.0;
// calculate the initial temporary value
double tempResult = middleValue * middleValue;
// loop while absolute difference between test value and original value
// is greater than the specified precision
// function: abs, from stdlib.h
while( abs( tempResult - value ) > SQRT_PRECISION )
{
// test for the temporary result to be greater than the original value
if( tempResult > value )
{
// set the upper value to the middle value
upperValue = middleValue;
}
// otherwise, assume the temporary result is less than the original value
else
{
// set the lower value to the middle value
lowerValue = middleValue;
}
// end test
// recalculate middle value
middleValue = ( lowerValue + upperValue ) / 2.0;
// recalculate the temporary result
tempResult = middleValue * middleValue;
}
// end loop
// return middle value
return middleValue;
}
/*
@ -168,8 +245,15 @@ Dependencies: as needed (library utilities may not be used)
*/
int findStringLength( const char *str )
{
// returns an integer.
return 0;
// needs to iterate through the 'string' checking if the character is NULL.
// if character not null, add one to count.
int index = 0;
while(str[index] != NULL_CHAR)
{
index = index + 1;
}
// returns an integer count of the number of characters.
return index;
}
/*
@ -185,8 +269,13 @@ Dependencies: as needed, including rand
*/
int getRandomLetterValue()
{
int currentRand = 0;
// generate random number between 1 and 52
currentRand = rand() % (NUM_ALPHABET_LETTERS + 1) + 1;
// then get the integer that character corresponds to and return it.
int letterInt = (int)ALPHABET[currentRand];
// returns an integer.
return 0;
return letterInt;
}
/*

BIN
PA01-0906/PA01_Main Executable file

Binary file not shown.

View file

@ -12,6 +12,20 @@
// 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);
/*
char toEncrypt[ HUGE_STR_LEN ], decryptedStr[ HUGE_STR_LEN ];
char fileName[ STD_STR_LEN ], stringFromFile[ HUGE_STR_LEN ];
SquareArrayType *encryptedInput, *uploadedInput;
@ -51,11 +65,12 @@ int main( int argc, char *args[] )
decryptData( stringFromFile, uploadedInput );
printf( "\nUploaded string: %s\n", stringFromFile );
*/
// end program
// clear arrays
encryptedInput = clearArrayType( encryptedInput );
// encryptedInput = clearArrayType( encryptedInput );
// display end of program
printf( "\nProgram End\n" );