Go Back

Programming Assignment 2: Modular Exponentiation Implementation

Demo is not required for this time. Please submit your codes as instructed. Due on 3:00 pm, 11/01/2018

Write a program (e.g., C, C++) to implement modular exponentiation using the algorithm described on page 23 of lecture 9 notes for public key cryptography. The requirements concerning your codes are

Your codes must pass the following test cases (a^b mod n = result):

a
b
n
result
00000001
12345678
12345678 
1
00000000
76543210
12345678
0
00000003
000fefef
00000008
3
00000005
32348232
00000011
8
34433445
6cff454f
00000011
9
7fffffff
7eeeeeee
7ddddddd 
74e6476c
77777777
34839432
23498834
1d61f4c9
0facade0
0decade0
0abbabad  
3e29b63

Turn in:

Your source code files, readme.txt describing how to run your code, and a report including screenshots of the results.
Programs will be graded primarily on correctness of output, but no credit will be given for programs which do not use the basic algorithm covered in the lecture notes.
Also, your codes must TAKE PARAMETERS (i.e., a, b, n), otherwise 25% credit will be deducted for this.

Hint: the product of two ints will often be too large to fit in an int and will overflow, but the product of two ints will always fit in a long.