This is an open-ended assignment, the goal of which is to give you
some idea of how public-key algorithms work, and also develop some
useful tools for future homework.
The goal: write code to implement arbitrary precision integer arithmetic.
Specifically, you want to be able to take numbers of hundreds or thousands of digits, and perform arithmetic with them. This will include:
How to do it
If you write in C or C++, you can create a datatype to hold arbitrarily big integers. For convenience, you can just use character strings. For instance, you can represent the hexadecimal number 123eef5 as the string "5fee321". I put that in reverse order because you'll find it's more convenient to do so. We will use hexadecimal because it is much easier.
For further convenience, you can use the typedef keyword to define a number datatype like so:
typedef char * number; |
Then, you'll need to define individual functions to handle these numbers: creating them by allocating space, filling them with data, and performing arithmetic. For example you could have:
|
Then you could have code in your main function like so:
number N, M, P, Q; |
The main function is unimportant. The important part is implementing the individual functions. They must be implemented as separate functions, because you will be using them as building blocks. For example, your multiply function can use your add function. Later, your exponent function will use your multiply function.
In the process, you may find yourself creating a few more functions for convenience sake.
Note: how are you going to represent negative numbers, and subtraction? That's up to you.