0

I am working on RSA algo but the numbers, on which different operations are performed, are very large. And Java operators are failing here.

I need to take modulus of a very large number (like this big 1.35858791876006E+75) but the normal % or bigDecimalObj.divideAndRemainder() function does not give me the correct answer.

Is there any other library (some .jar file) available that could help me out?

Bugs Happen
  • 2,169
  • 4
  • 33
  • 59
  • 1
    Can you show how you are trying? – Rahul Tripathi Oct 08 '15 at 12:07
  • There are algorithms for finding out modulus. See if this helps: http://stackoverflow.com/questions/2177781/how-to-calculate-modulus-of-large-numbers – pri Oct 08 '15 at 12:07
  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow" – Andy Turner Oct 08 '15 at 12:08
  • 1
    I think, standard Java classes can do this if used properly. Show us how you use them. – Tagir Valeev Oct 08 '15 at 12:21
  • I was simply doing `1.35858791876006E+75 % 77` and the answers given by Java and Windows' calculator were different, while calculator's answer was correct. – Bugs Happen Oct 09 '15 at 04:39

2 Answers2

1

You should consider BigInteger, it can handle big numbers. More specifically using mod() and modpow() can solve many overflow issues.

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
0

You should use BigInteger, You can look it from here http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html

burak buruk
  • 111
  • 1
  • 5