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

Discussion in 'Android Questions' started by KMatle, Jan 25, 2015.

  1. KMatle

    KMatle 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?
     
    wonder likes this.
  2. klaus

    klaus Expert Licensed User

    An exponant of 627423852959 looks very strange to me.
    What does this calulation represent or what is it for ?
     
  3. MLDev

    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: Jan 26, 2015
  4. KMatle

    KMatle Expert Licensed User

    I need it for RSA encryption

    @MLDev : Will try it...
     
  5. MLDev

    MLDev Active Member Licensed User

    I thought so. That algorithm is used in RSA.
     
    KMatle likes this.
  6. KMatle

    KMatle Expert Licensed User

    Thanks again. Now my B4A-RSA part is up and running. Will create a php script which does the same.
     
    Peter Simpson likes this.
  7. DonManfred

    DonManfred Expert Licensed User

    Creating RSA from within Basic4Android? :D
     
    Peter Simpson and KMatle like this.
  8. MLDev

    MLDev Active Member Licensed User

    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
     
  9. wonder

    wonder Expert Licensed User

    Upon performing your calculation, I might have accidentally opened a wormhole!
    [​IMG]

    [​IMG]
     
  10. KMatle

    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.
     
    MLDev and wonder like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice