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

KMatle

Expert
Licensed User

MLDev

Active Member
Licensed 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:

MLDev

Active Member
Licensed User
Creating RSA from within Basic4Android? :D
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. :D
 

wonder

Expert
Licensed 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
Licensed 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.
 
Top