Programming
implement and test 3 different algorithms for computing modular exponentiation:
1. Implement a function powerDirect(a, b, m) that takes three integers a, b, and m > 1. The function can compute the modular exponentiation ab modulo m.
2. Implement a function powerMemoryEfficient(a, b, m) that takes three integers a, b, and m > 1. The function can compute the modular exponentiation ab modulo m. This method requires more operations than the first method, because the required memory is substantially less, however, operations take less time than before. The end result is that the algorithm is faster.
3. Implement a function powerRightLeftBinary(a, b, m) that takes three integers a, b, and m > 1. The function can compute the modular exponentiation ab modulo m. This method drastically reduces the number of operations to perform modular exponentiation, while keeping the same memory footprint as in method 2. It is a combination of the method 2 and a more general principle called exponentiation by squaring (also known as binary exponentiation).
Required Information The following Wikipedia page includes required information about “Direct”, “Memoryefficient” and “Right-to-Left binary” algorithms:
https://en.wikipedia.org/wiki/Modular_exponentiation
1.powerDirect(a,b,m){
res=1
if(m>1){
while(y>0){
a=a%m
if (y%2==1)
res=(res*x)%m
b=b-1
x=(x*x)%p
}
}
return res
}
2.powerMemoryEfficient(a,b,m)
{
if (a== 0)
return 0;
if (b == 0)
return 1;
// If B is even
long y;
if (a % 2 == 0) {
y = powerMemoryEfficient(a, b / 2, c);
y = (y * y) % c;
}
// If B is odd
else {
y = A % C;
y = (y * exponentMod(a, b - 1, c) % c) % c;
}
return (int)((y + c) % c);
}
3.powerRightLeftBinary(a, b, m){
if m = 1 then return 0
Assert :: (m - 1) * (m - 1)
result = 1
a =a %m
while b > 0
if (e%2 == 1):
result := (result * a) %m
b = b>> 1
a= (a * a)%m
return result
}
Programming implement and test 3 different algorithms for computing modular exponentiation: 1. Implement a function powerDirect(a,...
(a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search function...
Write code to implement the following function: /* * Generate mask indicating leftmost 1 in x. Assume w=32. * For example 0xFF00 -> 0x8000, and 0x6600 --> 0x4000. * If x = 0,then return 0. */ int leftmost_one(unsigned x); Your function should follow the above bit-level integer coding rules, except that you may assume that data type int has w=32 bits. Your code should contain a total of at most 15 arithmetic, bit-wise, and logical operations. In C++ and has...
Programming Assignment 1 Data structure Java Implement Shellsort for a linked list, based on a variant of bubble sort. The rather severe constraints imposed by the singly-linked list organization presents special problems for implementing Shellsort. Your task is to overcome these constraints and develop a simple, elegant implementation that does not sacrifice efficiency or waste space. Step 1. First, implement a routine to build a list: read integers from standard input, and build a list node for each item consisting...
Use C++
forehand e receiver creates a public key and a secret key as follows. Generate two distinct primes, p andq. Since they can be used to generate the secret key, they must be kept hidden. Let n-pg, phi(n) ((p-1)*(q-1) Select an integer e such that gcd(e, (p-100g-1))-1. The public key is the pair (e,n). This should be distributed widely. Compute d such that d-l(mod (p-1)(q-1). This can be done using the pulverizer. The secret key is the pair (d.n)....
This was the answer I got, teacher said it was wrong
Teacher said, couldnt run the gate because there wasnt any
switches
5. Design and test a simplified logic circuit to identify all numbers in the output range of function: F(x) = 2x+3 for an input domain between 0 and 6. Be sure to include your truth table. Normal 1 No Spac... Heading 1 Head Paragraph Styles t Draw Simulate View Window Help 39 ) ) 11:55 1 esu.desire2learn.com Boolean...
1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...
hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...
C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.] Write a rational number class. Recall that a rational number is a ratio-nal number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects...
Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...
Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...