# Other[Solved] How to solve "Power(236475,627423852959) Mod 46373" by code (simplifying)

#### KMatle

##### Expert
As the exponent is very large of

Power(236475,627423852959) Mod 46373

I have to simplify the calculation.

I've found a lot of sources (but no example how to do this by code) can anyone help me here?

• wonder

#### MLDev

##### Active Member
You can use the "Russian Peasant Method" of multiplication algorithm:

Log(powerMod(236475, 627423852959, 46373))

Sub powerMod(base As Double, exponent As Double, n As Double) As Double
Dim M As Double = 1

Do While exponent <> 0
If exponent Mod 2 = 1 Then M = (M * base) Mod n
base = (base * base) Mod n
exponent = Floor(exponent / 2)​
Loop

Return M​
End Sub

Last edited:

#### MLDev

##### Active Member
I thought so. That algorithm is used in RSA.

• KMatle

#### KMatle

##### Expert
• Peter Simpson

#### DonManfred

##### Expert
Will create a php script which does the same.
Creating RSA from within Basic4Android? • Peter Simpson and KMatle

#### MLDev

##### Active Member
Creating RSA from within Basic4Android? RSA is easy to implement within B4A. Using that algorithm you can encrypt and decrypt messages and find large primes for keys. But using Doubles it not secure though. The key size should be a minimum of 1024 bits. I haven't tried it but the BigNumbers library should work. It'll probably be slow though. #### wonder

##### Expert
As the exponent is very large of

Power(236475,627423852959) Mod 46373

I have to simplify the calculation.

I've found a lot of sources (but no example how to do this by code) can anyone help me here?
Upon performing your calculation, I might have accidentally opened a wormhole!  #### KMatle

##### Expert
• 