I have created this basic program to implement the Diffie-Hellman algorithm. I want s
to be a randomly generated prime number, and q
to be a randomly generated integer. sk1
and sk2
are shared keys which are also generated randomly. pk1
and pk2
are modulus calculated values which I have to prove are equal to each other. I think my formula is correct but I am not sure how to print the values of s
, q
, sk1
, sk2
, pk1
and pk2
to verify my requirements. My code is pasted below and I would really appreciate if anyone could help me with the print statements.
package javaapplication1;
import java.util.Random;
import java.math.*;
public class DH {
public static void main(String [] arg) {
int s, q;
double sk1, sk2, pk1 = 0, pk2 = 0;
Random generator = new Random();
s = generator.nextInt(50000);
q = generator.nextInt(50000);
sk1 = generator.nextInt();
sk2 = generator.nextInt();
if(s==1 || s==2) {
for(int i = 2; i< (int)(s/2); i++) {
if(s/i != (int)(s/i)) {
double a= Math.pow(q,sk1);
pk1 = a%s;
double b= Math.pow(q, sk2);
pk2 = b%s;
if(pk1==pk2) {
System.out.println("true");
}
System.out.println(s);
System.out.println(q);
System.out.println(sk1);
System.out.println(sk2);
System.out.println(pk1);
System.out.println(pk2);
}
}
}
}
}