All pastes #737077 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-15 02:36 UTC
rendered paste body
import java.lang.Exception;
import java.io.IOException;
import java.io.PrintStream;

class RSA{

public static long GCD(long x, long y) 
{	long[]	u = {1, 0, x}; 
	long[] 	v = {0, 1, y}; 
	long[]  t = new long[3]; 
	while (v[2] != 0)
	{	long q = u[2]/v[2];
		for (int i = 0; i < 3; i++)
		{ t[i] = u[i] - v[i]*q; 
		  u[i] = v[i]; v[i] = t[i]; 
		} 
	} 
	return u[0]; 
}

public static void main (String args[])  throws java.lang.Exception
{	long p=0, q=0, e=0, d, n, phi_n;
	try
	{	
		p = Long.parseLong(args[0]);
		q = Long.parseLong(args[1]);
		e = Long.parseLong(args[2]);
	}
	catch(ArrayIndexOutOfBoundsException aE)
	{	System.out.println("Thrown to indicate that an array has been accessed with an illegal index." + aE.getMessage());
	}
	
	n = p * q;
	phi_n = (p - 1) * (q - 1);
	d = GCD(e, phi_n);
	
	/*
	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(n);
	System.out.println(e);
	System.out.println(d);
	
} // end main

}// end class RSA