MnMWizard icon

Untitled

MnMWizard | PRO | 10/27/17 02:08:33 PM UTC | 0 ⭐ | 386 👁️ | Never ⏰ | []
text |

1.64 KB

|

None

|

0 👍

/

0 👎

//Mason Marnell - Since the code was conflicting due to the same characters being used, 
//I slightly modified the encoded characters to make it work.
 import java.io.*;
import java.util.*;
 	public class Crypto {		
 		public String encrypt(String toEncr){
		String toRet = toEncr.replaceAll("v", "ay'r");
				toRet = toRet.replaceAll("V", "AY'R");
				toRet = toRet.replaceAll("M", "SSAD");
				toRet = toRet.replaceAll("m", "ssad");
				toRet = toRet.replaceAll("g", "jef..w");
				toRet = toRet.replaceAll("G", "JEF..W");
				toRet = toRet.replaceAll("b", "dul>/");
				toRet = toRet.replaceAll("B", "DUL>/");
				return toRet;
 		}
 		public String decrypt(String toDecr) {
	String toRet = toDecr.replaceAll("ay'r", "v");
			toRet = toRet.replaceAll("AY'R", "V" );
			toRet = toRet.replaceAll("ssad", "m");
			toRet = toRet.replaceAll("SSAD","M");
			toRet = toRet.replaceAll("JEF..W", "G");
			toRet = toRet.replaceAll("jef..w", "g");
			toRet = toRet.replaceAll("DUL>/", "B");
			toRet = toRet.replaceAll("dul>/", "b");
			return toRet;
		}
 	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
         System.out.print("Enter a sentence that is to be encrypted:");
         String sntnc = sc.nextLine();
         System.out.println("Original sentence =  "+ sntnc);
         Crypto myCryptObj = new Crypto();
         String encryptdSntnc = myCryptObj.encrypt(sntnc);
         System.out.println("Encrypted sentence = " + encryptdSntnc); 
         String decryptdSntnc = myCryptObj.decrypt(encryptdSntnc);
         System.out.println("Decrypted sentence = " + decryptdSntnc);
 	}
}

Comments