Advertisement
MnMWizard

Untitled

Oct 27th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. //Mason Marnell - Since the code was conflicting due to the same characters being used,
  2. //I slightly modified the encoded characters to make it work.
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class Crypto {
  8.  
  9. public String encrypt(String toEncr){
  10. String toRet = toEncr.replaceAll("v", "ay'r");
  11. toRet = toRet.replaceAll("V", "AY'R");
  12. toRet = toRet.replaceAll("M", "SSAD");
  13. toRet = toRet.replaceAll("m", "ssad");
  14. toRet = toRet.replaceAll("g", "jef..w");
  15. toRet = toRet.replaceAll("G", "JEF..W");
  16. toRet = toRet.replaceAll("b", "dul>/");
  17. toRet = toRet.replaceAll("B", "DUL>/");
  18. return toRet;
  19.  
  20. }
  21.  
  22. public String decrypt(String toDecr) {
  23. String toRet = toDecr.replaceAll("ay'r", "v");
  24. toRet = toRet.replaceAll("AY'R", "V" );
  25. toRet = toRet.replaceAll("ssad", "m");
  26. toRet = toRet.replaceAll("SSAD","M");
  27. toRet = toRet.replaceAll("JEF..W", "G");
  28. toRet = toRet.replaceAll("jef..w", "g");
  29. toRet = toRet.replaceAll("DUL>/", "B");
  30. toRet = toRet.replaceAll("dul>/", "b");
  31. return toRet;
  32. }
  33.  
  34. public static void main(String[] args) {
  35. Scanner sc = new Scanner(System.in);
  36.  
  37. System.out.print("Enter a sentence that is to be encrypted:");
  38.  
  39. String sntnc = sc.nextLine();
  40.  
  41. System.out.println("Original sentence = "+ sntnc);
  42.  
  43. Crypto myCryptObj = new Crypto();
  44.  
  45. String encryptdSntnc = myCryptObj.encrypt(sntnc);
  46.  
  47. System.out.println("Encrypted sentence = " + encryptdSntnc);
  48.  
  49. String decryptdSntnc = myCryptObj.decrypt(encryptdSntnc);
  50.  
  51. System.out.println("Decrypted sentence = " + decryptdSntnc);
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement