Modular Exponentiation
Learn how to efficiently compute the modular exponentiation with the help of some examples and a flowchart.
We promised you that we would go through some of the mathematical details of the RSA algorithm. If you are not interested in the details, feel free to skip to the next section.
Modular exponentiation means that we want to find , given general integers , , and , where
In other words, is the remainder of dividing by . We could use a brute force method to find : calculate and then divide by to find the remainder . The difficulty is that , , and might be large numbers, which need to be stored as exact binary sequences, and is extremely large and must be stored exactly. Also, carrying out the division by will be time consuming. However, once we have chosen and , there is a simple algorithm to find that avoids the large number issues:
- Set .
- Increase by .
- Set .
- If , go to step 2. Otherwise, is the solution to .
Note that serves as an index to keep track of the loops through the algorithm. Here is a flow chart for the algorithm:
Get hands-on with 1400+ tech skills courses.