The CSIS Problem You have just been hired by CSIS in their cryptography division. You are working with their encryption algorithm that happens to use an encryption strategy called RSA. (You can read more about RSA encryption on your own time). Essentially, all you need to know is that RSA works with numbers, really big numbers, like numbers that have, on average, 400 digits. Your job is to help out your Senior developer by making large numbers easier to work with. Write a C# program called HugeNumber.cs. It should have two fields 1. A string that holds the value of the number 2. An int that holds how many digits are in the number (The leng
The CSIS Problem
You have just been hired by CSIS in their cryptography division. You are working with their encryption
Essentially, all you need to know is that RSA works with numbers, really big numbers, like numbers that have, on average, 400 digits.
Your job is to help out your Senior developer by making large numbers easier to work with.
Write a C# program called HugeNumber.cs. It should have two fields
1. A string that holds the value of the number
2. An int that holds how many digits are in the number (The length of the string).
It should also have:
3. A constructor that only takes the value as a parameter. The number of digits should be calculated
4. A public Display method that simply returns the value of the nuber
5. A method called NumDigits() that returns the number of digits in the number (This can be a property if you're feeling frisky).
6. A method called EndsWith() that returns the digit in the one's place (should be an int)
7. A comptareTo method (more on that below)
Your job is to implement a CompareTo method for these numbers.
CmpareTo(HugeNumber o) should returns -1 if the current value is less than o's value, 0 if they are equal, and 1 if its larger.
The only caveat here is that you are not allowed to use the String's built in CompareTo methods - it's too slow while working with these numbers.
You cannot use BigInt / BigDouble
To test your application, put the following code in Program.cs inside of a main method.
Please also submit this file :D
HugeNumber num1 = new HugeNumber("4000000000000000000000000000000000000000000000000000000000000000000001")
HugeNumber num2 = new HugeNumber("4000000000000000000000000000000000000000000000000000000000000000000002")
Console.WriteLine(num1.CompareTo(num2)) // -1
HINT:
First check the length of both Huge Numbers. If they are different, then figuring out whether to return 1 or -1 should be easy.
If the numbers have the same number of digits, just loop through the string and find the first value that's larger. That HugeNumber must be bigger than the other.
How to loop through a string in C#
foreach (char c in someString)
{
// You don't need to convert c to an integer. The relative difference is the same.
}
Step by step
Solved in 3 steps with 2 images