fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.io.*;
  6. import java.util.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11.  
  12. public static void main(String args[])
  13. {
  14. Scanner kbReader = new Scanner(System.in);
  15. System.out.print("Enter a sentence that is to be encrypted:");
  16. String sntnc = kbReader.nextLine();
  17. System.out.println("\nOriginal Sentence = " + sntnc);
  18.  
  19. Crypto myCryptObj = new Crypto();
  20. String encryptdSntnc = myCryptObj.encrypt(sntnc);
  21. System.out.println("Encrypted sentence = " + encryptdSntnc);
  22.  
  23. String decryptdSntnc = myCryptObj.decrypt(encryptdSntnc);
  24. System.out.println("Decrypted sentence = " + decryptdSntnc);
  25. }
  26.  
  27. }
  28.  
  29. class Crypto
  30. {
  31. public String x1;
  32.  
  33. public String acceptor(String sntnc)
  34. {
  35. String x1 = sntnc;
  36. return x1;
  37. }
  38.  
  39. public String encrypt(String sntnc)
  40. {
  41. x1 = sntnc;
  42.  
  43. x1 = x1.replaceAll("[vV]", "1"); // 1
  44. x1 = x1.replaceAll("[mM]", "2"); // 2
  45. x1 = x1.replaceAll("[gG]", "3"); // 3
  46. x1 = x1.replaceAll("[bB]", "4"); // 4
  47.  
  48. x1 = x1.replaceAll("1", "ag',r");
  49. x1 = x1.replaceAll("2", "ssad");
  50. x1 = x1.replaceAll("3", "jeb..w");
  51. x1 = x1.replaceAll("4", "dug>?/");
  52.  
  53.  
  54.  
  55. return x1;
  56. }
  57.  
  58. public String decrypt(String sntnc)
  59. {
  60. x1 = sntnc;
  61.  
  62. x1 = x1.replaceAll("dug\\>\\?/","4");
  63. x1 = x1.replaceAll("jeb\\.\\.w","3");
  64. x1 = x1.replaceAll("ssad","2");
  65. x1 = x1.replaceAll("ag',r","1");
  66.  
  67. x1 = x1.replaceAll("4","B");
  68. x1 = x1.replaceAll("3","G");
  69. x1 = x1.replaceAll("2","M");
  70. x1 = x1.replaceAll("1","V");
  71.  
  72. return x1;
  73. }
  74. }
  75.  
Success #stdin #stdout 0.09s 381632KB
stdin
This is a very big morning.
stdout
Enter a sentence that is to be encrypted:
Original Sentence = This is a very big morning.
Encrypted sentence = This is a ag',rery dug>?/ijeb..w ssadorninjeb..w.
Decrypted sentence = This is a Very BiG MorninG.