Question

Programming implement and test 3 different algorithms for computing modular exponentiation: 1. Implement a function powerDirect(a,...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

}

Add a comment
Know the answer?
Add Answer to:
Programming implement and test 3 different algorithms for computing modular exponentiation: 1. Implement a function powerDirect(a,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int...

    (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....

    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...

  • Use C++ forehand e receiver creates a public key and a secret key as follows. Generate...

    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...

    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...

    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...

    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.]...

    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) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    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...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Problem Set 2: Inheritance and Method Overriding The goal of this problem set is to apply...

    Problem Set 2: Inheritance and Method Overriding The goal of this problem set is to apply inheritance and method overriding in order to create a hierarchy of array sorters. There exist many algorithms to sort arrays. In this problem set, we are especially interested in “in-place” sorting algorithms like Selection Sort and Insertion Sort. In-place sorting refers to an approach in which we perform the sorting steps on the underlying array rather than using extra storage. When using object-oriented design,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT