RSA public Key cryptography was developed in 1977 by Ron Rivest, Adi Shamirh and Lenadleman (Massachusetts Institute of America).
The algorithm's name is also their three person initials, the RSA algorithm is based on a very simple number theory fact:
Multiplying the two large primes is easy, but it is extremely difficult to factorization the product, so the product can be exposed as the encryption key.
Package RSA; Import Java.math.BigInteger; public class RSA {private Long p,q,e,d,n; Public RSA () {int pindex = (int) (Math.random () *10); int qindex; int eindex; do{qindex = (int) (Math.random () *10); } while (Qindex==pindex); do{eindex = (int) (Math.random () *10); } while (Eindex==pindex| | Eindex==pindex); p = 1033; Q = 2017; e = 29437; n = p*q; D = calculated (); } private Long calculated () {Long T0 = 0,t1 = 1,t2 =-1; Long R0 = (p-1) * (q-1), m = R0,R1 = e, r2 =-1; do{long q = R0/R1; r2 = r0-r1*q; if (r2==0) break; t2 = t0-t1*q; while (t2<0) {t2+=m; } if (t2>=m) {t2%= m; } r0 = r1; r1 = R2; t0 = t1; T1 = T2; }while (r2!=0); if (r1!=1) {return 0; } else{return T2; }} public Long Gete () {return e; } public Long Getn () {return n; } public Long getd () {return D; Public BigInteger encode (BigInteger data) {return POW (data,d). MoD (New BigInteger (n+ "")); } public BigInteger decode (BigInteger code) {return POW (code,e). MoD (New BigInteger (n+ "")); Public BigInteger pow (BigInteger Data,long p) {data = Data.pow ((int) p); return data; } public static void Main (String args[]) {RSA RSA = new RSA (); BigInteger data = new BigInteger ("222222"); Long oldtime = System.currenttimemillis (); BigInteger code = rsa.encode (data); Long newtime = System.currenttimemillis (); Double codetime = ((double) (newtime-oldtime))/1000; Oldtime = System.currenttimemillis (); BigInteger decode = Rsa.decode (code); NewTime = System.currenttimemillis (); Double decodetime = ((double) (newtime-oldtime))/1000; System.out.println ("Privatekey:" +RSA.D); System.out.println ("Publickkey:" +RSA.E); System.out.println ("N:" +RSA.N); SYSTEM.OUT.PRINTLN ("Data:" +data); System.out.println ("Code:" +code+ "Time:" +codetime); System.out.println ("Decode:" +decode+ "Time:" +decodetime); } }
RSA Public Key cryptography algorithm