int main(void) { int values[10] = {3, 7, -9, 3, 6, -1, 7, 9, 1, -5}; printf("The sum is %i\n", arraySum(values, 10)); return 0; }
int main ( void ) { int array[5] = { 1, 32, 31, 314, 5435 }; int arraySum (int array[], int n); printf ( "The sum of the array is %i.\n", arraySum (array, 5) ); return 0; }
void inverse_round(bit block[block_length], bit key[key_length]){ arraySum(block , key , block , block_length); inverse_mixingLayer(block); inverse_sboxLayer(block); }
void round(bit block[block_length], bit key[key_length]){ sboxLayer(block); mixingLayer(block); arraySum(block , key , block , block_length); }
void test_arraySum(int * array, int len, int expected) { printArray(array, len); int sum = arraySum(array, len); printf(". sum = %d, expected = %d.", sum, expected); if(sum != expected) printf(" FAIL"); printf("\n"); }
int main(int argc, char **argv) { int arraySum(int *array, const int n); int values[10] = {3, 7, -9, 3, 6, -1, 7, 9, 1, -5}; printf("The sum is %i\n", arraySum(values, 10)); return 0; }
int main(void) { int arraySum(int array[], int index); int array[2], i, index=2, result; for (i=0; i<index; ++i) { array[i] = 2; } result = arraySum(array, 2); printf("The result is: %i", result); return 0; }
void mixingLayerMatrixMul(bit block[block_length] , bit result_chunk[chunk_length], unsigned int column){ int i; for(i = 0; i < chunk_length; i++) result_chunk[i] = 0; for(i = 0; i < 4; i++) { bit chunk[chunk_length]; getChunk(block , chunk , i); arrayMul(chunk , mixingMatrix[i][column] , primitivePoly , chunk , primitivePolyDegree); arraySum(result_chunk , chunk , result_chunk , chunk_length); } }
void bunny24_encrypt(bit block[block_length] , bit key[key_length]){ //blockInversion(block); //blockInversion(key); bit keys[16][key_length]; keySchedule(key , keys); int i; arraySum(block , keys[0] , block , block_length); // first XOR for(i = 1; i <= 3; i++) // 15 rounds round(block , keys[i]); //blockInversion(block); //blockInversion(key); }
void bunny24_decrypt(bit block[block_length] , bit key[key_length]){ //blockInversion(block); //blockInversion(key); bit keys[16][key_length]; keySchedule(key , keys); int i; for(i = 3; i > 0; i--) // 15 rounds inverse_round(block , keys[i]); arraySum(block , keys[0] , block , block_length); // first XOR //blockInversion(block); //blockInversion(key); }
int main(int argc, char * * argv) { printf("it begins\n\n"); int tarray[] = {0, 2, 1}; int tarraylen = 3; int tsum = arraySum(tarray, tarraylen); int tnegs = arrayCountNegative(tarray, tarraylen); int tups = arrayIsIncreasing(tarray, 0); int tind = arrayIndexRFind(4, tarray, tarraylen); int tmin = arrayFindSmallest(tarray, tarraylen); //printf("%d\n", tsum ); //printf("%d\n", tnegs); printf("%d\n", tups); //printf("%d\n\n", tind); //printf("%d\n\n", tmin); return EXIT_SUCCESS; }
void keySchedule(bit key[key_length] , bit schedule[16][key_length]){ //Step 1 bit word[88][6]; int i , j , r; for(i = 0; i < 4; i++){ getChunk(key, word[i], i); for(j = 0; j < chunk_length; j++) word[i + 4][j] = word[i][j]; } for(i = 4; i < 8; i++) { sbox(word[i], i - 4); if(i < 7) arraySum(word[i - 3] , word[i] , word[i] , chunk_length); else arraySum(word[0] , word[i] , word[i] , chunk_length); } //step 2 for(j = 9; j <= 88; j++) { i = j-1; if((j % 8) == 1) { bit buffer[chunk_length]; arrayCopy(word[i - 1] , buffer , chunk_length); rotate(buffer, -1 , chunk_length); sbox(buffer , 1); arraySum(buffer , word[i - 8], word[i], chunk_length); arraySum(word[i], keyScheduleArray , word[i], chunk_length); } else if((j % 8) == 5) { bit buffer[chunk_length]; arrayCopy(word[i - 1] , buffer , chunk_length); sbox(buffer , 2); arraySum(word[i - 8] , buffer , word[i] , chunk_length); } else if((j % 4) != 1) arraySum(word[i - 8] , word[i - 1] , word[i] , chunk_length); } //phase 3 for(r = 0; r < 3; r++) //for rect 1,2,3 { for(j = 0; j < 5; j++) //for key 1...5 { int z = (8 + 20*r) + j; int index = (r*5)+j; for(i = 0; i < 4; i++) //for each word of the key { setChunk(schedule[index] , word[z] , i); z += 5; } } } int z = 68; for(i = 0; i < 4; i++) //last key { setChunk(schedule[15] , word[z] , i); z += 5; } }
int main(int argc, char* argv[]) { if (argc < 3)//cmd line arguments { std::cout << "Error! Error!" << std::endl; std::cout << "Argument 1 is the program name" << std::endl; std::cout << "Argument 2 is input file for greedy and dynamic programming algorithms." << std::endl; std::cout << "Argument 3 is input file for brute force algorithm" << std::endl; return 1; } //Hold input and output file names std::string input_filename;//Holds filename of first input file. std::string output_filename;//Holds filename of first output file. std::string input_filename2;//Holds filename of second input file. std::string output_filename2;//Holds filename of second output file. //Modify first output file name input_filename = argv[1];//Getting the first input filename via command line output_filename = input_filename;//Getting name for first output file output_filename.erase(output_filename.end() - 4, output_filename.end() - 0);//remove .txt from filename output_filename.append("change.txt");//appending change.txt to output_filename //Modify second output file name input_filename2 = argv[2];//Getting the second input filename via command line output_filename2 = input_filename2;//Getting name for second output file output_filename2.erase(output_filename2.end() - 4, output_filename2.end() - 0);//remove .txt from filename output_filename2.append("change.txt");//appending change.txt to output_filename std::cout << "1st INPUT FILE " << input_filename << std::endl; std::cout << "1st OUTPUT FILE " << output_filename << std::endl; std::cout << std::endl; std::cout << "2nd INPUT FILE " << input_filename2 << std::endl; std::cout << "2nd OUTPUT FILE " << output_filename2 << std::endl; std::cout << std::endl; std::string inputFile = input_filename;//first Input file name. std::ifstream if_inputStream;//input stream for first input file. std::string inputFile2 = input_filename2;//second Input file name. std::ifstream if_inputStream2;//input stream for second input file. //For first input file std::string tempFile = "temp.txt";//temp file name. std::fstream f_tempStream;//temp stream for temp file. //For second input file std::string tempFile2 = "temp2.txt";//temp2 file name. std::fstream f_tempStream2;//temp2 stream for temp file. std::string outputFile = output_filename;//first output file name. std::ofstream outputStream;//first output stream for output file. std::string outputFile2 = output_filename2;//second output file name. std::ofstream outputStream2;//second output stream for output file. output_file_check(outputStream, output_filename);//Checks if first output file is opened. output_file_check(outputStream2, output_filename2);//Checks if second output file is opened. if_file_check(if_inputStream, inputFile);//Checks to see if first input file is opened. if_file_check(if_inputStream2, inputFile2);//Checks to see if second input file is opened. f_file_check(f_tempStream, tempFile);//Check if temp file is opened f_file_check(f_tempStream2, tempFile2);//Check if temp2 file is opened std::vector<int> relay;// Holds values from array in first input file. std::vector<int> relay2;// Holds values from array in second input file. std::vector<int> coins;// Coins to calculate value from first input file. std::vector<int> coins2;// Coins to calculate value from second input file. int value;// Value to find with coins from first input file. int value2;// Value to find with coins from second input file. int arrayCount = 0;//Number of arrays in first input file. int arrayCount2 = 0;//Number of arrays in second input file. double time = 0; //Holds time for each array to be processed, used for greedy and DP algorithm run time double greedyTotalTime = 0;//Total run time for greedy algorithm double dpTotalTime = 0;//Total run time for DP algorithm //Variables used for brute force algorithm coinChange answer;//Keeps track of number of each coin used answer.num = 0; int minCoin;//Keeps track of total coins used. std::vector<int> storeCoin;//Vector to hold amount of each coin used. double bruteForceTotalTime = 0;//Total run time for brute force algorithm clock_t start, stop;//Used for calculating run time for brute force algorithm. //Strip first input file strip_file(if_inputStream, f_tempStream); //stripping first input file of [] and , arrayCount = numofArrays(f_tempStream, tempFile);//Get count of number of arrays in first file. //Strip second input file strip_file(if_inputStream2, f_tempStream2); //stripping second input file of [] and , arrayCount2 = numofArrays(f_tempStream2, tempFile2);//Get count of number of arrays in second file. //Iterate through the first input file for each array. Runs Greedy and DP algorithms for (int i = 1; i <= arrayCount + 1; i++) { //First input file relay = lineToVector(f_tempStream, tempFile, relay, i);//Populates relay vector with values. if (i % 2 != 0) { coins = relay;//Set coins vector equal to relay. relay.clear();//Clears the relay vector of all values. } else { value = relay[0];//Set value to the only index with a value in relay /***************************GREEDY ALGORITHM**********************************/ //time = name_for_greedy_algorithm_function(outputStream, coins, value); //greedyTotalTime += time; //time = 03 /***************************DP ALGORITHM**************************************/ //time = name_for_dp_algorithm_function(outputStream, coins, value); //dpTotalTime += time; //time = 0; relay.clear();//Clears the relay vector of all values. coins.clear();//Reset coins vector value = 0;//Reset value } } //Iterate through the second input file for each array. Runs brute force algorithm for (int i = 1; i <= arrayCount2 + 1; i++) { //Reset timers; start = 0; stop = 0; //Second input file relay2 = lineToVector(f_tempStream2, tempFile2, relay2, i);//Populates relay vector with values. if (i % 2 != 0) { coins2 = relay2;//Set coins vector equal to relay. relay2.clear();//Clears the relay vector of all values. } else { value2 = relay2[0];//Set value to the only index with a value in relay int arraySize2 = coins2.size(); start = clock();//Start timer answer = bruteForce(coins2, value2, arraySize2); stop = clock();//stop timer bruteForceTotalTime += (stop - start) / double(CLOCKS_PER_SEC); storeCoin.resize(arraySize2);//Sets the size of the amount of coins vector for (int i = 0; i < arraySize2; i++) { storeCoin[i] = answer.coinCount[i]; } minCoin = arraySum(answer.coinCount, arraySize2); outputStream2 << "Brute Force Algorithm" << std::endl; outputStream2 << "["; for (int i = 0; i < arraySize2; i++) { if (i < (arraySize2 - 1)) { outputStream2 << storeCoin[i] << ", "; } else { outputStream2 << storeCoin[i]; } } outputStream2 << "]"; outputStream2 << '\r' << '\n'; outputStream2 << minCoin << std::endl; outputStream2 << '\r' << '\n'; outputStream2 << '\r' << '\n'; relay2.clear();//Clears the relay vector of all values. coins2.clear();//Reset coins vector value2 = 0;//Reset value } } std::cout << "Alg1: Brute Force Run-time is: " << bruteForceTotalTime << std::endl; std::cout << "Alg2: Greedy Run-time is: " << greedyTotalTime << std::endl; std::cout << "Alg3: Dynamic Programming Run-time is: " << dpTotalTime << std::endl; //Closing file streams if_inputStream.close(); if_inputStream2.close(); f_tempStream.close(); f_tempStream2.close(); outputStream.close(); outputStream2.close(); return 0; };//end main