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

#### KMatle

##### Expert
Longtime User
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?

#### klaus

##### Expert
Longtime User
An exponant of 627423852959 looks very strange to me.
What does this calulation represent or what is it for ?

#### MLDev

##### Active Member
Longtime User
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:

Longtime User

#### MLDev

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

#### KMatle

##### Expert
Longtime User
Thanks again. Now my B4A-RSA part is up and running. Will create a php script which does the same.

#### DonManfred

##### Expert
Longtime User
Will create a php script which does the same.
Creating RSA from within Basic4Android?

#### MLDev

##### Active Member
Longtime User
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
Longtime User
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
Longtime User
Using symetric encryption is very suboptimal because you have to exchange the keys which MUST be protected (the one who has the key can decrypt everything). It's very fragile.

The only safe way is to use RSA. As you know the public key is public and can be exchanged in any way you like. Messages can only be encrypted with the privat key which is kept secret.

Agraham has an library which supports RSA. App2App communication works safe with it. The problem is when you want to communicate with a server. Most hosters don't allow you to use OpenSSL or other libs, except you pay (a lot of) money for it. Even if you buy it, I did not find a way to make the keys byte compatible.

However. Usually you use php for the server part. So there is a need to have RSA here without a lib or other components. I've finished the B4A logic yesterday. In the next weeks I will develop the php script and write a tutorial.

Replies
21
Views
11K
Android Question [Solved] Power bug?
Replies
3
Views
618
Replies
2
Views
779
Replies
10
Views
3K
Replies
14
Views
6K