Code example for BigInteger

Methods: modPow, subtract, toString

0
		v.loadUrl("file:///android_asset/redez_start.html");
		setContentView(v);
	} 
	 
	public void displayDHDemo() {  // DH DEMO 
		BigInteger g = new BigInteger("2");
		BigInteger m = new BigInteger(Rfc3526Modulus1536Bits, 16);
 
		SecureRandom rand = new SecureRandom();
		BigInteger secA = new BigInteger(NumRandomBitsPerDHKey, rand);
		BigInteger secB = new BigInteger(NumRandomBitsPerDHKey, rand);
		// Each raises g to the secret key to get the public key. 
		BigInteger pubA = g.modPow(secA, m);
		BigInteger pubB = g.modPow(secB, m);
		// A learns pubB; B learns pubA. 
		BigInteger mutualA = pubB.modPow(secA, m);  // A can compute.
		BigInteger mutualB = pubA.modPow(secB, m);  // B can compute.
		// Those mutual keys should be equal. 
		BigInteger mutualDiff = mutualA.subtract(mutualB);
		 
		String html = "<html><body><ul>";
		html += "<li> secA = " + secA;
		html += "<li> secB = " + secB;
		html += "<li> pubA = " + pubA;
		html += "<li> pubB = " + pubB;
		html += "<li> mutualA = " + mutualA;
		html += "<li> mutualB = " + mutualB;
		html += "<li> mutualDiff = " + mutualDiff;
		html += "<li> len(mutual) = " + mutualA.toString().length() + " decimal digits";
		 
		DemoWebView v = new DemoWebView(mainContext, html);
		setContentView(v);
	}