Home / Expert Answers / Computer Science / please-help-in-c-also-please-put-all-code-into-one-file-and-not-in-5-different-cpp-files-please-pa136

(Solved): Please help in C++. Also, please put all code into ONE file and not in 5 different .cpp files please ...



Please help in C++. Also, please put all code into ONE file and not in 5 different .cpp files please. And please provide screenshots of the code working, Thank you!

Write a \( \mathrm{C}++ \) program following the instructions below. Please follow the order of the tasks given below, and wr3. Find Relatively Prime
Write a function to return a number that is relatively prime with the given number.
/* return an int1. Pick two prime numbers \( \mathbf{p}, \mathbf{q} \), for example,
- const int \( \mathrm{P}=23 \);
- const int \( Q=17 \);1. Due to the \( c++ \) compiler issue, \( c++ \) might cannot handle the operation of raising an integer to a large power. H

Write a program following the instructions below. Please follow the order of the tasks given below, and write one function a time, test it, and then move on to the next function. 1. Implement Euclidean Algorithm for calculating greatest common divisor First write and test a function that calculates the greatest common divisor of two nonnegative integers, as follows: * precondition: postcondition: return int EuclidAlgGCD (int , int ); Then implement the extended Euclidean Algorithm to find not only the greatest common divisor of two integers, but also find the integer coefficients that expresses the gcd in terms of the integers, as illustrated below: precondition: postcondition: return and are set so that int ExtendedEuclidAlgGCD (int , int , int \& , int \& ); 2. Modular arithmetic Write a function that returns the result of any integer modulo of (i.e., reduce the integer modulo ). Note that the operator can be used, but it returns a negative value, for example, yields -1 , so we need to do something adjustment (recall that because . Therefore, we will use the function from this step to implement the later encode() and decode() functions. 3. Find Relatively Prime Write a function to return a number that is relatively prime with the given number. /* return an integer that is relatively prime with , and greater than 1 i.e., the god of the returned int and is 1 Note: Although , we don't want to return * int RelativelyPrime (int ) 4. Find Inverse Then implement the following function, which returns the inverse modulo, and test it. Note that you need to check whether and are relative prime before calling this function. Recall that and are relatively prime means that , i.e., their greatest common divisor is 1 . Also recall that the extended Euclidean Algorithm can find the integer and for and such that , where is the inverse of modulo . 1. Pick two prime numbers , for example, - const int ; - const int ; - int ; 2. Find a that is relatively prime with Call RelativelyPrime () 3. Calculate the inverse modulo of to be your Use inverse () 4. Write a function Encode as follows: - // Return M^e mod PQ - int Encode (int , int , int ); 5. Write a function Decode as follows: - //Return mod PQ - int Decode (int , int , int ); 6. Verify that RSA algorithm works, i.e., - int ; - * is an integer that is smaller than - cout "Enter an integer that is smaller than" ; - ; - Encode ; - Decode ; - assert (M==M1); //Note: include assert.h header file to use this //macro/function. 1. Due to the compiler issue, might cannot handle the operation of raising an integer to a large power. Here is an instance of and that can work: , pick , then , so 5 is the inverse of ) 2. If we want to randomly generate two initial prime numbers, then we need a function to test primality. Use the definition of prime number to guide your implementation of the following function. For any positive integers , , if , then or / return true if is prime return false if is not prime Precondition: bool IsPrime (int )


We have an Answer from Expert

View Expert Answer

Expert Answer



1) This C++ program calculates the greatest common divisor using the Euclidean and Extended Euclidean algorithms.



By sending the two numbers a and b into the main function, we have tested the ExtendedEuclidAlgGCD function. The function determines the integer coefficients s and t that express the greatest common divisor (gcd) in terms of the integers along with the greatest common divisor of a and b. The console is then printed with the results.
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe