Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 654309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:28:49+00:00 2026-05-13T22:28:49+00:00

I have to port some crypto code to visual c++ from java which (visual

  • 0

I have to port some crypto code to visual c++ from java which (visual c++) I am not very familiar with. I found a library at http://sourceforge.net/projects/cpp-bigint/ that I can use for big integers.

However it does not have an equivalent to javas SecureRandom class. I did find a project in c++ called beecrypt but could not get it to work with Visual Studio 2008.

Does anyone have any experience with these types of libraries? I saw gmp too but couldn’t find one that worked with visual studio off the bat.

Before I head down the wrong road any advice?

Thanks!

—-UPDATE——-

I seem to have a proof of concept working with the cpp-bigint from above with small numbers. In the library there is no modPow function. For now I created a for loop like:

for(RossiBigInt i("0",DEC_DIGIT); i< r; i++)

{
x = x * g;
x = x % p;
}

This gives me x = g^r mod p but it is very slow. Does anyone know of other BitInteger libraries with the modPow function or know a faster way for me to compute this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:28:50+00:00Added an answer on May 13, 2026 at 10:28 pm

    The modPow function can be evaluated efficiently with a “square and multiply” algorithm. In Java it would look like this (if Java’s BigInteger did not already have it):

    /* Compute x^n mod m. */
    static BigInteger modPow(BigInteger x, BigInteger n, BigInteger m)
    {
        if (n.signum() < 0)
            throw new IllegalArgumentException("bwah, negative exponent");
        BigInteger r = BigInteger.ONE;
        for (int i = n.bitLength() - 1; i >= 0; i --) {
            if (n.testBit(i))
                r = r.multiply(x).mod(m);
            if (i > 0)
                r = r.multiply(r).mod(m);
        }
        return r;
    }
    

    With this, the number of loop iteration is equal to the length, in bits, of the exponent, so that the computational time is acceptable.

    You still get one or two modular reductions per iteration, so this will not be the fastest exponentiation algorithm ever (modular reductions are substantially more expensive than multiplication). Typical modPow() implementations use Montgomery reduction, which is a clever trick which merges all modular reduction into a single similar operation at the end.

    If you have time, implementing your own modular exponentiation would be very pedagogical; you would start by reading chapter 14 of the “Handbook of Applied Cryptography”, freely downloadable from this site. However, in this harsh world where mundane considerations of budget often limit creativity and free time, you would probably be happy with an already implemented library. GMP is known to be quite good, but somewhat difficult to use on Windows. You may have better luck with NTL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple client server code written java(server listens on some port
I'm using Zend_Search_Lucene, the PHP port of Java Lucene. I currently have some code
I have to port some C# code to Java and I am having some
I am trying to port some code from Delphi to C# and I have
I'm trying to port some of my c++ code into c. I have the
I have some iptables rules which redirect requests for port 80 onto our application
I have to port the build of a DLL from building in Visual Studio
Hi i have to port some stuff written on c++ from unix bases os
I am trying to port some code which runs fine on Linux to Win32.
I'm trying to port some Octave code to Java. I'm trying out atan2 so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.