# Excel returns error when raising numbers to a very large power

I'm experimenting with modular arithmetic and large numbers (getting more and more into cryptography).

I'm trying to do problems along the line of 3027^253 mod 3233 and Excel is returning errors.

I thought of breaking up the problem to something along the line of

(1000^253 mod 3233) + (1000^253 mod 3233) + (1000^253 mod 3233) + (27^253 mod 3233)

but that doesn't work either. I can't get much larger than

(10^253 mod 3233) so that doesn't really help.

It may very well be that Excel can't handle this sort of problem. If that's the case what will?

In case it matters my programming level is low - decent javascript and basic PHP (can interact with a database).

EDIT:

Javascript also bugs out:

Math.pow(1000, 253); returns Infinity. As does Math.pow(100, 253);

• Have you tried using Excel's 64-bit version? – Ƭᴇcʜιᴇ007 Jun 8 '16 at 18:22
• @Ƭᴇcʜιᴇ007 - No. Using Office 2010 32 bit. – Mayo Jun 8 '16 at 19:03

Here is some code based on the common algorithm:

``````Public Function xMod(baseV As Long, pwr As Long, modV As Long) As Long
Dim i As Long

xMod = 1
For i = 1 To pwr
xMod = xMod * baseV
xMod = xMod - Int(xMod / modV) * modV
Next i
End Function
``````

But, sadly, I have no idea if it is working! ..................is this what you expect ?? : (it does agree with the Wolfram Widget)

• Yes. I like that. Will try it. – Mayo Jun 8 '16 at 18:27
• @Mayo Please let me know if you find a bug. – Gary's Student Jun 8 '16 at 18:53
• Perfect!!!! Thx. – Mayo Jun 8 '16 at 19:18

One solution is going to Wolfram | Alpha's Modulo Widget

It's fast and handles these problems easily.