Package P3;
Import Java.util.HashMap;
Import Java.util.Map;
public class Encryption {//String str;
Static map<character,character> map=new hashmap<character,character> ();
Static Map<character,character>map1=new hashmap<character,character> ();
Encryption () {String a= "abcdefghijklmnopqrstuvwsvz*";
String b= "Veknohzf*iljxdmygbrcswqupta";
for (int i=0;i<a.length (); i++) {Map.put (A.charat (i), B.charat (i));
Map1.put (B.charat (i), A.charat (i));
} public static string encrypt (String str) {string s2= str.tolowercase ();
String d = "";
for (int i = 0; i < s2.length (); i++) {d = d + map.get (S2.charat (i));
return D;
public static string decrypt (String str) {string d = "";
for (int i = 0; i < str.length (); i++) {d = d + map1.get (Str.charat (i));
return D;
}
}
The entire method is loaded into the class, it needs to be encrypted and decrypted just call
Encryption e1=new encryption ();
String stre= "Hello*world";
String Stre1=e1.encrypt (stre);
System.out.println (stre1);
System.out.println (E1.decrypt (stre1));
The program used for testing
Output results:
Fojjmaqmbjn
Hello*world