Maximum Infinity | Sololearn: Learn to code for FREE!

+1

Maximum Infinity

https://code.sololearn.com/cwXXGJd7Btd9/?ref=app 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.

10/20/2020 5:52:15 PM

Sebastian Ahlborn

3 Answers

New Answer

0

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.