Question: You should write your code in C++ to match the pseudocode for each algorithm 4. Write a program where you implement Modular Exponentiation (ME) using
You should write your code in C++ to match the pseudocode for each algorithm
4. Write a program where you implement Modular Exponentiation (ME) using the square and multiply approach as a function which is called in main. ME calculates a*k mod n. The program should get values for a, k and n from the user. This code requires two steps. First k must be converted to a binary representation K consisting of a list of Os and 1s. Second, Modular Exponentiation must be performed using a, n and K[] as arguments procedure BinaryK(k) K empty list //hint: make K a vector tmp-k while tmp>0 add y mod 2 to K //hint: use pushback tmp -(tmp-K[i)/2 return K procedure ModularExpo(a, K, n) if n 1 return 0 ifk 0 return b if KI0] 1 for i 1 to length(K)-1 A- A*A mod n if K[i] 1 b- A*b mod n return b
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
