All pastes #734747 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-12 23:27 UTC
rendered paste body
import java.lang.Exception;
import java.io.IOException;
import java.io.PrintStream;

class RSA{

private static long gcd(long m, long n) 
{	while (n != 0)
	{	long rem = m % n;
		m = n;
		n = rem;
	}
    return m;
}

public static void main (String args[])  throws java.lang.Exception
{	long p, q, e, d, n, phi_n;
	
	p = Long.parseLong(args[0]);
	q = Long.parseLong(args[1]);
	e = Long.parseLong(args[2]);
	
	n = p * q;
	phi_n = (p - 1) * (q - 1);
	
	d = (long)Math.pow( e, -1) % phi_n; // not correct at all, the (long) typecast truncates the decimal
	
	System.out.println("p = " + p);
	System.out.println("q = " + q);
	System.out.println("e = " + e);
	System.out.println("d = " + d);
	System.out.println("n = " + n);
	System.out.println("phi(n) = " + phi_n);
	System.out.println("gcd(" + e +", " + phi_n +") = " + gcd(e, phi_n));  // value should be 1
} // end main

}// end class RSA