Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
get negative D, when I try to generate private key RSA

I have the method to calculate D(private key) for RSA. The method uses extended Euclidean algorithm. So sometimes I get negative D and it isn't right how I can fix it? D * e mod (p-1)(q-1)=1; here is the code of the method

public static BigInteger extEuclid(BigInteger a, BigInteger b)
{

        BigInteger x = BigInteger.ZERO, y = BigInteger.ONE, lastx = BigInteger.ONE, lasty = BigInteger.ZERO, temp;
        while (!b.equals(BigInteger.ZERO))
        {
            BigInteger q = a.divide(b);
            BigInteger r = a.mod(b) ;
        a = b;
        b = r;

        temp = x;
        x = lastx.subtract(q.multiply(x));
        lastx = temp;

        temp = y;
        y = lasty.subtract(q.multiply(y));
        lasty = temp;
    }

    return lastx;
}


public void calcD(){
  d = extEuclid(e, fEuler);
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!