Reputation: 53
I am trying to figure out how to compute large powers of huge numbers in matlab to do RSA encryption.
For example: A 50+ digit integer raised to the power of 999999.
Upvotes: 3
Views: 2468
Reputation: 7193
We need to implement some form of large number data type
For C this is done using GMP Multiprecision library or LibToMMath Library
There are many others as well
For Matlab may be this will be helpful
>>> LInK <<<
Upvotes: 0
Reputation: 11168
So the end result will be around 1e49^1e6 = 1e49000000
. This is too large a number for any basic matlab datatype to hold. A solution is to use the vpi toolbox of the file exchange; it can handle large numbers, at the cost of speed.
A better solution would exist in getting your end objective on a different manner; ie redefine the formulas to get the final result..
Upvotes: 2
Reputation: 16055
You can use exponentiation by squaring:
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
Upvotes: 3