I have written a short function to calculate a power of a number modulo N. I can get out of the range of any integer like type, so I've written a loop, that calculates only modulus values:
Function ModPwr(b As Integer, e As Integer, m As Integer) As Integer
Dim r As Integer
r = 1
Do While e > 0
r = r * b Mod m
e = e - 1
Loop
ModPwr = r
End Function
The function collapses or return zero for some input (eg: 217, 143, 221). If I completly remove all "As Integer" and the Dim declaration, everything works fine:
Function ModPwr(b, e, m)
r = 1
Do While e > 0
r = r * b Mod m
e = e - 1
Loop
ModPwr = r
End Function
I have to implement an RSA demo in Excel to demonstrate the encryption/decryption method (using small primes!). I am a newby in VBA.
In other (more complicated) functions I need the type declaration, so I have to find the problem.