fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. BigInteger c = null;
  14. BigInteger d = null;
  15. BigInteger phi = null;
  16. BigInteger e =null;
  17. BigInteger m = null;
  18.  
  19. Scanner sc=new Scanner(System.in);
  20. System.out.print("Enter keysize(default = 1024):");
  21.  
  22. try{
  23. String key=sc.next();
  24. bitLength = Integer.parseInt(key);
  25. }catch(NoSuckElementExveption exp){
  26. bitLength = KEYSIZE_EDFAULT;
  27. }catch(NumberFormatException exp){
  28. System.out.println("Wrong key size! Using default.");
  29. }
  30.  
  31. SecureRandom scrRnd = new SecureRandom();
  32. do{
  33. pPrime = BigInteger.probablePrime(bitLength,scrRnd);
  34. }while (pPrime.bitLength()<bitLength);
  35. do{
  36. qPrime = BigInteger.probablePrime(bitLength,scrRnd);
  37. }while (qPrime.bitLength()<bitLength);
  38.  
  39. System.out.println("p = "+pPrime);
  40. System.out.println("q = "+qPrime);
  41.  
  42. BigInteger n = pPrime.multiply(qPrime);
  43. System.out.println("n = "+n);
  44.  
  45. phi=pPrime.subtrcat(BigInteger.ONE).multiply(qPrime.subtract(BigInteger.ONE));
  46. System.out.println("phi = "+phi);
  47.  
  48. do{
  49. do{
  50. e=BigInteger.probablePrime(bitLength,scrRnd);
  51. }while((e.bitLength()<bitLength) || (e.compareTo(phi)>=0));
  52. }while(phi.remainder(e).intValue()==0);
  53. System.out.println("e = "+e);
  54.  
  55. d=e.modInverse(phi);
  56. System.out.println("d = "+d);
  57.  
  58. System.out.println("Public Key{n,e}={"+n+","+e+"}");
  59. System.out.println("Private Key{n,d}={"+n+","+d+"}");
  60.  
  61. System.out.println("Enter Encrypting value: ");
  62. m=new BigInteger(sc.next());
  63. c=m.modPow(e,n);
  64. System.out.println("Ciphertext value = "+c);
  65. System.out.println("Decrypting value...");
  66. BigInteger.plaintext = c.modPow(d,n);
  67. System.out.println("Plaintext value="+plaintext);
  68.  
  69. }
  70. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1024 1024
compilation info
Main.java:24: error: cannot find symbol
			bitLength = Integer.parseInt(key);
			^
  symbol:   variable bitLength
  location: class Ideone
Main.java:25: error: cannot find symbol
		}catch(NoSuckElementExveption exp){
		       ^
  symbol:   class NoSuckElementExveption
  location: class Ideone
Main.java:26: error: cannot find symbol
			bitLength = KEYSIZE_EDFAULT;
			^
  symbol:   variable bitLength
  location: class Ideone
Main.java:26: error: cannot find symbol
			bitLength = KEYSIZE_EDFAULT;
			            ^
  symbol:   variable KEYSIZE_EDFAULT
  location: class Ideone
Main.java:31: error: cannot find symbol
		SecureRandom scrRnd = new SecureRandom();
		^
  symbol:   class SecureRandom
  location: class Ideone
Main.java:31: error: cannot find symbol
		SecureRandom scrRnd = new SecureRandom();
		                          ^
  symbol:   class SecureRandom
  location: class Ideone
Main.java:33: error: cannot find symbol
			pPrime = BigInteger.probablePrime(bitLength,scrRnd);
			^
  symbol:   variable pPrime
  location: class Ideone
Main.java:33: error: cannot find symbol
			pPrime = BigInteger.probablePrime(bitLength,scrRnd);
			                                  ^
  symbol:   variable bitLength
  location: class Ideone
Main.java:34: error: cannot find symbol
		}while (pPrime.bitLength()<bitLength);
		        ^
  symbol:   variable pPrime
  location: class Ideone
Main.java:34: error: cannot find symbol
		}while (pPrime.bitLength()<bitLength);
		                           ^
  symbol:   variable bitLength
  location: class Ideone
Main.java:36: error: cannot find symbol
			qPrime = BigInteger.probablePrime(bitLength,scrRnd);
			^
  symbol:   variable qPrime
  location: class Ideone
Main.java:36: error: cannot find symbol
			qPrime = BigInteger.probablePrime(bitLength,scrRnd);
			                                  ^
  symbol:   variable bitLength
  location: class Ideone
Main.java:37: error: cannot find symbol
		}while (qPrime.bitLength()<bitLength);
		        ^
  symbol:   variable qPrime
  location: class Ideone
Main.java:37: error: cannot find symbol
		}while (qPrime.bitLength()<bitLength);
		                           ^
  symbol:   variable bitLength
  location: class Ideone
Main.java:39: error: cannot find symbol
		System.out.println("p = "+pPrime);
		                          ^
  symbol:   variable pPrime
  location: class Ideone
Main.java:40: error: cannot find symbol
		System.out.println("q = "+qPrime);
		                          ^
  symbol:   variable qPrime
  location: class Ideone
Main.java:42: error: cannot find symbol
		BigInteger n = pPrime.multiply(qPrime);
		                               ^
  symbol:   variable qPrime
  location: class Ideone
Main.java:42: error: cannot find symbol
		BigInteger n = pPrime.multiply(qPrime);
		               ^
  symbol:   variable pPrime
  location: class Ideone
Main.java:45: error: cannot find symbol
		phi=pPrime.subtrcat(BigInteger.ONE).multiply(qPrime.subtract(BigInteger.ONE));
		                                             ^
  symbol:   variable qPrime
  location: class Ideone
Main.java:45: error: cannot find symbol
		phi=pPrime.subtrcat(BigInteger.ONE).multiply(qPrime.subtract(BigInteger.ONE));
		    ^
  symbol:   variable pPrime
  location: class Ideone
Main.java:50: error: cannot find symbol
				e=BigInteger.probablePrime(bitLength,scrRnd);
				                           ^
  symbol:   variable bitLength
  location: class Ideone
Main.java:51: error: cannot find symbol
			}while((e.bitLength()<bitLength) || (e.compareTo(phi)>=0));
			                      ^
  symbol:   variable bitLength
  location: class Ideone
Main.java:66: error: cannot find symbol
		BigInteger.plaintext = c.modPow(d,n);
		          ^
  symbol:   variable plaintext
  location: class BigInteger
Main.java:67: error: cannot find symbol
		System.out.println("Plaintext value="+plaintext);
		                                      ^
  symbol:   variable plaintext
  location: class Ideone
24 errors
stdout
Standard output is empty