Maximum Infinity | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Maximum Infinity Hi, this is my RSA-encryption code. But it throws an exception: the result would be too large. What is the reason? How can I avoid this? Hoping I will get some answers, S.A.

20th Oct 2020, 5:52 PM
Sebastian Ahlborn
Sebastian Ahlborn - avatar
1 Answer
This is the line giving you trouble: m = m.pow(d.intValue()); likely because d is massive and it totally overflows after that power operation. You should be able to fix this using something like exceptions, checking to see if the number is in range first, or just a smaller number in the first place. When tinkering with your numbers, I have to reduce d to 7 digits to not throw an exception but it still times out, and then 5 digits to get the code to work.
20th Oct 2020, 6:03 PM
Maxwell Anderson
Maxwell Anderson - avatar