RSA Code in Java
RSA Code in Java
Share 1
Apple
Translate
Select Language
Followers
Join this site
w ith Google Friend Connect
Members (11)
public class RSA { private BigInteger p; private BigInteger q; private BigInteger N; private BigInteger phi; private BigInteger e; private BigInteger d; private int bitlength = 1024; private int blocksize = 256; //blocksize in byte private Random r; public RSA() { r = new Random(); p = BigInteger.probablePrime(bitlength, r); q = BigInteger.probablePrime(bitlength, r); N = p.multiply(q); phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE)); e = BigInteger.probablePrime(bitlength/2, r); while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0 ) { e.add(BigInteger.ONE); } d = e.modInverse(phi); } public RSA(BigInteger e, BigInteger d, BigInteger N) { this.e = e; this.d = d; this.N = N; } public static void main (String[] args) throws IOException { RSA rsa = new RSA(); DataInputStream in=new DataInputStream(System.in); String teststring ; System.out.println("Enter the plain text:"); teststring=in.readLine(); System.out.println("Encrypting String: " + teststring); System.out.println("String in Bytes: " + bytesToString(teststring.getBytes())); // encrypt byte[] encrypted = rsa.encrypt(teststring.getBytes()); System.out.println("Encrypted String in Bytes: " + bytesToString(encrypted)); // decrypt byte[] decrypted = rsa.decrypt(encrypted);
Subscribe To
Posts Comments
Popular Posts
RSA code in Java To encrypt and decrypt a string using RSA algorithm The following code helps the user to provide a string for encryption and decry... Round Robin Process Scheduling Algorithm in C++ Round Robin Process Scheduling Algorithm in C++ Here is my own written code in C++ for Round Robin process scheduling algorit... Liang-Barsky line clipping program in c++ Liang-Barsky line clipping program in c++ This is my own code in c++ for LiangBarsky line clipping algorithm : Source code: #inclu... COHEN SUTHERLAND line clipping code in C++ COHEN SUTHERLAND line clipping code in C++ Here is my own generated code for
1/3
whereskyisnotthelimit.blogspot.in/2012/04/rsa-code-in-java.html
3/8/13
Cohen Sutherland line clipping algorithm in C++.Hope its us... C++ Code for generating Sierpinski gasket (triangle) C++ Code for generating Sierpinski gasket (triangle) My code for generating fractal using C++. Programming fractals is very interest... C++ CODE FOR POLYGON CLIPPING C++ CODE FOR POLYGON CLIPPING So here's my C++ code for Polygon Clipping.This program can clip ant polygon except recta... DDA algorithm using DOSBox 0.74 Hello friends!!Here is a code for DDA line drawing algorithm which prints the line pixel by pixel.The code is written in C++ and executed u... FLOOD FILL ALGORITHM FLOOD FILL ALGORITHM This my own code for polygon filling using the flood dill algorithm. Hope you enjoy this! Source code: #inclu...
5 comments: krish October 7, 2012 at 8:04 AM sonali what if i want to encrypt a file... Reply Replies Sonali Dinkar October 8, 2012 at 10:39 AM
Bresenham line drawing algorithm Bresenham line drawing algorithm My code for Bresenham line drawing algorithm which will help you to learn how the algorithm actua... Connecting PCs in LAN Local Area Network Connection This is what I learn t and explored during my project training in BARC..so very eager to share it wit...
About Me
I haven't tried programming on that but try this link..i think this will solve ur problem.. http://www.c.happycodings.com/File_Operations/code2.html
Sonali Dinkar
Verdy Yanto January 5, 2013 at 12:22 AM i want to ask why if i decrease a bit length the decryption text it can be symbol? not a text? Reply Replies Sonali Dinkar January 8, 2013 at 8:25 AM
2013 (3) 2012 (52) October (1) September (4) August (7) July (4)
2/3
I didnt get your doubt..if you mean that the decrypted text on reducing the bit length
whereskyisnotthelimit.blogspot.in/2012/04/rsa-code-in-java.html
3/8/13
May (4) April (6) Just go for it!!: Primitive chat program using XML... Primitive chat program using XMLRPC Just go for it!!: RSA code in Java RSA code in Java Just go for it!!: Remove hyperlinks from a word fi... Remove hyperlinks from a word file at a time! March (12) February (6)
E n t e ry o u rc o m m e n t . . .
Newer Post
Subscribe to: Post Comments (Atom)
Home
Older Post
January (8)
whereskyisnotthelimit.blogspot.in/2012/04/rsa-code-in-java.html
3/3