MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.math.BigInteger;

public class MainClass {
    public final static int pValue = 47;

    public final static int gValue = 71;

    public final static int XaValue = 9;

    public final static int XbValue = 14;

    public static void main(String[] args) throws Exception {
        BigInteger p = new BigInteger(Integer.toString(pValue));
        BigInteger g = new BigInteger(Integer.toString(gValue));
        System.out.println("p = " + p);
        System.out.println("g = " + g);

        BigInteger Xa = new BigInteger(Integer.toString(XaValue));
        BigInteger Xb = new BigInteger(Integer.toString(XbValue));
        System.out.println("Xa = " + Xa);
        System.out.println("Xb = " + Xb);

        BigInteger Ya = g.modPow(Xa, p);
        System.out.println("Ya = " + Ya);

        BigInteger Yb = g.modPow(Xb, p);
        System.out.println("Yb = " + Yb);

        BigInteger Ka = Ya.modPow(Xa, p);
        System.out.println("Users A, K = " + Ka);

        BigInteger Kb = Yb.modPow(Xb, p);
        System.out.println("Users B, K = " + Kb);

    }

}