public class PubKey1 { public static long[] prime = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 433494437L, 2971215073L }; public static long p, q; public static long n, m; public static long enc, dec; public static long encrypt( long x ) { long out = 1; System.out.println("input >> " + x); for (int i=0; i < enc; i++ ) { out = (out*x)%n; System.out.println("enc>> " + out); } return out; } public static long decrypt( long x ) { long out = 1; System.out.println("input >> " + x); for (int i=0; i < dec; i++ ) { out = (out*x)%n; System.out.println("dec>> " + out); } return out; } public static void main( String[] args ) { p = prime[5]; q = prime[3]; n = p*q; m = (p-1)*(q-1); for ( enc = 7; enc < n; enc++ ) { if ( m % enc != 0 ) break; } for ( dec = 1; dec < n; dec++ ) { if ( (dec*enc)%m == 1 ) break; } System.out.println("prime 1 p = " + p); System.out.println("prime 2 q = " + q); System.out.println("n (p*q) = " + n); System.out.println("m ((p-1)*(q-1)) = " + m); System.out.println("enc (m not div by enc) = " + enc); System.out.println("dec (= not div by enc) = " + dec); long m, x, y; m = 131; x = encrypt(m); System.out.println(); y = decrypt(x); System.out.println("m = " + m + " Encrypted = " + x + " Decrypted = " + y ); } }