I greet you this day,
These are the solutions to Mathematics questions on Modular Arithmetic and Algorithms.
The TI-84 Plus CE shall be used for applicable questions.
If you find these resources valuable/helpful, please consider making a donation:
Cash App: $ExamsSuccess or
cash.app/ExamsSuccess
PayPal: @ExamsSuccess or
PayPal.me/ExamsSuccess
Google charges me for the hosting of this website and my other
educational websites. It does not host any of the websites for free.
Besides, I spend a lot of time to type the questions and the solutions well.
As you probably know, I provide clear explanations on the solutions.
Your donation is appreciated.
Comments, ideas, areas of improvement, questions, and constructive
criticisms are welcome.
Feel free to contact me. Please be positive in your message.
I wish you the best.
Thank you.
In Modular Exponentiation, we want to calculate: an integer raised to a nonnegative integer modulo a
positive
integer.
Say we have: $a^b \mod n$,
$a$ and $b$ are nonnegative integers
$n$ is a positive integer
If $b$ is very large, the calculation of $a^b \mod n$ cannot be done with a calculator.
Hence, we need to find how to solve such calculations.
Modular Exponentiation is one of the concepts used in Cryptology.
Cryptology is the study of writing and cracking secret messages.
Specifically, modular exponentiation is used in the RSA (Rivest, Shamir, Adelman) cryptosystem for secured data
transmissions.
There are four methods of solving modular exponentiation.
They are:
(1.) Method of Fast Modular Multiplication
(2.) Method of Repeated Squaring using the Modular Exponentiation Algorithm
(3.) Fermat's Little Theorem
(4.) Fermat's Little Theorem and the Chinese Remainder Theorem
Let us review the algorithms used in these four methods.
For $i = 5$
$b_5 = 1$
$c = 2c$
$c = 2 * 0$
$c = 0$
$d = (d * d) \mod n$
$d = (1 * 1) \mod 317$
$d = 1 \mod 317$
$d = 1$
But $b_5 = 1$
$c = c + 1$
$c = 0 + 1$
$c = 1$
$d = (d * a) \mod n$
$d = (1 * 3) \mod 317$
$d = 3 \mod 317$
$d = 3$
We shall not initial again. The initialization is for the first case.
For $i = 4$
$b_4 = 1$
$c = 2c$
$c = 2 * 1$
$c = 2$
$d = (d * d) \mod n$
$d = (3 * 3) \mod 317$
$d = 9 \mod 317$
$d = 9$
But $b_4 = 1$
$c = c + 1$
$c = 2 + 1$
$c = 3$
$d = (d * a) \mod n$
$d = (9 * 3) \mod 317$
$d = 27 \mod 317$
$d = 27$
For $i = 3$
$b_3 = 1$
$c = 2c$
$c = 2 * 3$
$c = 6$
$d = (d * d) \mod n$
$d = (27 * 27) \mod 317$
$d = 729 \mod 317$
$d = 95$
But $b_3 = 1$
$c = c + 1$
$c = 6 + 1$
$c = 7$
$d = (d * a) \mod n$
$d = (95 * 3) \mod 317$
$d = 285 \mod 317$
$d = 285$
For $i = 2$
$b_2 = 0$
$c = 2c$
$c = 2 * 7$
$c = 14$
$d = (d * d) \mod n$
$d = (285 * 285) \mod 317$
$d = 81225 \mod 317$
$d = 73$
But $b_2 = 0$
Stop.
For $i = 1$
$b_1 = 0$
$c = 2c$
$c = 2 * 14$
$c = 28$
$d = (d * d) \mod n$
$d = (73 * 73) \mod 317$
$d = 5329 \mod 317$
$d = 257$
But $b_1 = 0$
Stop.
For $i = 0$
$b_0 = 1$
$c = 2c$
$c = 2 * 28$
$c = 56$
$d = (d * d) \mod n$
$d = (257 * 257) \mod 317$
$d = 66049 \mod 317$
$d = 113$
But $b_0 = 1$
$c = c + 1$
$c = 56 + 1$
$c = 57$
$d = (d * a) \mod n$
$d = (113 * 3) \mod 317$
$d = 339 \mod 317$
$d = 22$
$i$ | $5$ | $4$ | $3$ | $2$ | $1$ | $0$ |
$b_i$ | $1$ | $1$ | $1$ | $0$ | $0$ | $1$ |
$c$ | $1$ | $3$ | $7$ | $14$ | $28$ | $57$ |
$d$ | $3$ | $27$ | $285$ | $73$ | $257$ |
$22$ return $d$ |
$\therefore 3^{57} \mod 317 = 22$ |
For $i = 9$
$b_9 = 1$
$c = 2c$
$c = 2 * 0$
$c = 0$
$d = (d * d) \mod n$
$d = (1 * 1) \mod 645$
$d = 1 \mod 645$
$d = 1$
But $b_9 = 1$
$c = c + 1$
$c = 0 + 1$
$c = 1$
$d = (d * a) \mod n$
$d = (1 * 11) \mod 645$
$d = 11 \mod 645$
$d = 11$
We shall not initial again. The initialization is for the first case.
For $i = 8$
$b_8 = 0$
$c = 2c$
$c = 2 * 1$
$c = 2$
$d = (d * d) \mod n$
$d = (11 * 11) \mod 645$
$d = 121 \mod 645$
$d = 121$
But $b_8 = 0$
Stop.
For $i = 7$
$b_7 = 1$
$c = 2c$
$c = 2 * 2$
$c = 4$
$d = (d * d) \mod n$
$d = (121 * 121) \mod 645$
$d = 14641 \mod 645$
$d = 451$
But $b_7 = 1$
$c = c + 1$
$c = 4 + 1$
$c = 5$
$d = (d * a) \mod n$
$d = (451 * 11) \mod 645$
$d = 4961 \mod 645$
$d = 446$
For $i = 6$
$b_6 = 0$
$c = 2c$
$c = 2 * 5$
$c = 10$
$d = (d * d) \mod n$
$d = (446 * 446) \mod 645$
$d = 198916 \mod 645$
$d = 256$
But $b_6 = 0$
Stop.
For $i = 5$
$b_5 = 0$
$c = 2c$
$c = 2 * 10$
$c = 20$
$d = (d * d) \mod n$
$d = (256 * 256) \mod 645$
$d = 65536 \mod 645$
$d = 391$
But $b_5 = 0$
Stop.
For $i = 4$
$b_4 = 0$
$c = 2c$
$c = 2 * 20$
$c = 40$
$d = (d * d) \mod n$
$d = (391 * 391) \mod 645$
$d = 152881 \mod 645$
$d = 16$
But $b_4 = 0$
Stop.
For $i = 3$
$b_3 = 0$
$c = 2c$
$c = 2 * 40$
$c = 80$
$d = (d * d) \mod n$
$d = (16 * 16) \mod 645$
$d = 256 \mod 645$
$d = 256$
But $b_3 = 0$
Stop.
For $i = 2$
$b_2 = 1$
$c = 2c$
$c = 2 * 80$
$c = 160$
$d = (d * d) \mod n$
$d = (256 * 256) \mod 645$
$d = 65536 \mod 645$
$d = 391$
But $b_2 = 1$
$c = c + 1$
$c = 160 + 1$
$c = 161$
$d = (d * a) \mod n$
$d = (391 * 11) \mod 645$
$d = 4301 \mod 645$
$d = 431$
For $i = 1$
$b_1 = 0$
$c = 2c$
$c = 2 * 161$
$c = 322$
$d = (d * d) \mod n$
$d = (431 * 431) \mod 645$
$d = 185761 \mod 645$
$d = 1$
But $b_1 = 0$
Stop.
For $i = 0$
$b_0 = 0$
$c = 2c$
$c = 2 * 322$
$c = 644$
$d = (d * d) \mod n$
$d = (1 * 1) \mod 645$
$d = 1 \mod 645$
$d = 1$
But $b_0 = 0$
Stop.
$i$ | $9$ | $8$ | $7$ | $6$ | $5$ | $4$ | $3$ | $2$ | $1$ | $0$ |
$b_i$ | $1$ | $0$ | $1$ | $0$ | $0$ | $0$ | $0$ | $1$ | $0$ | $0$ |
$c$ | $1$ | $2$ | $5$ | $10$ | $20$ | $40$ | $80$ | $161$ | $322$ | $644$ |
$d$ | $11$ | $121$ | $446$ | $256$ | $391$ | $16$ | $256$ | $431$ | $1$ |
$1$ return $d$ |
$\therefore 11^{644} \mod 645 = 1$ |
© 2025 Exams Success Group:
Your
Success in Exams is Our Priority
The Joy of a Teacher is the Success of his
Students.