So, I use java to find the RSA password public key. Right now I do not know what I am doing, and if it is right.
I have this information for the public key.
C = 5449089907
n = p*q = 8271344041
q = 181123
p = n/q = 45667
d = 53
phi(n) = (p-1)(q-1) = 8271117252
Which complicates BigIntegers things, numbers are a huge path for int and longs, so I have to use the clumsy BigIntegers. As far as I understand, I have the following equation to solve.
e*5198987987 - x*8271117252 = 1
I am trying to use the euclidean algorithm to solve it. In Java, I think I can use the following method:
I base the code on phi (n) = 8271117252 and d = 53. Then I use gcd in the for loop, trying out the numbers I from the for loop in gdc on phi (n). If the result is 1, I set e to iteration number i. Then I use the inverse module function on e and phi (n). If and only if it is equal to phi (n), I got a response. (I think it can be as bad as it gets).
Anyway, here is the code. Typically, any entry would be awesome, as it infuriated me.
import java.math.BigInteger;
public class RSADecrypt {
BigInteger p = new BigInteger("53");
BigInteger r = new BigInteger("8271344041");
BigInteger variabel_i;
BigInteger modinv;
BigInteger e;
public RSADecrypt () {
for (BigInteger bi = BigInteger.valueOf(1000000000);
bi.compareTo(BigInteger.ZERO) > 0;
bi = bi.subtract(BigInteger.ONE)) {
if(gcdThing(bi).equals(BigInteger.ONE))
e = bi;
if(modinv(e) == p) {
System.out.println(" I er "+ bi);
}
}
System.out.println("Ikke noe svar for deg!");
}
public BigInteger gcdThing(BigInteger i) {
BigInteger b2 = new BigInteger(""+i);
BigInteger gcd = r.gcd(b2);
return gcd;
}
public BigInteger modinv (BigInteger e2) {
variabel_i = new BigInteger(""+e2);
modinv = r.modInverse(variabel_i);
return modinv;
}
}
source
share