Question

In: Computer Science

P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way...

P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called “leet” – short for “elite”. In essence, it was a simple character replacement algorithm, where a single “regular” character was replaced by one or more “leet” characters; numbers remained the same. Here’s one of the most readable versions: a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t 7 z Z c ( i 1 o 0 u U d D j j p P v \\/ e 3 k |< q Q w \\/\\/ f Ph l L r R x >< Note! You will need to know how to 1) get the length of a string (the number of characters) and 2) access individual characters of the string. You must use at least one method in addition to main – preferably one that translates individual characters! Note #2: your first task should be to try to print out a single ‘\’ character…

In java Please

Solutions

Expert Solution

Code:-

//Import for input read
//Map for comparison
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class LeetConversion {


public static void main(String[] args) {
//Variable for leet text generation
String leet="";
//Scanner object for input read
Scanner sc=new Scanner(System.in);
//Prompt for input teaxt for conversion
System.out.print("Enter a test for conversion: ");
String text=sc.nextLine();
//Call method to get length of the entered string
int len=StringLength(text);
//Loop unti end of the string to gete character by character
for(int i=0;i<len;i++) {
//Call method to get correspoding leet code
String str=getLeet(text.charAt(i));
//If function return a code then add it into the leet
if(str!=null) {
leet+=str;
}
//Otherwise same character add into leet
else {
leet+=text.charAt(i);
}
}
//Display leet text
System.out.println("Leet text of the given text is "+leet);
  
}
//Method to find length of the string
public static int StringLength(String text) {
return text.length();
}
//Method to find the leet form of a character
public static String getLeet(char ch) {
//MAp for mapping character and leet expression
Map<Character,String> leetComp=new HashMap<Character,String>();
leetComp.put('a',"4");
leetComp.put('b',"B");
leetComp.put('c',"(");
leetComp.put('d',"D");
leetComp.put('e',"3");
leetComp.put('f',"Ph");
leetComp.put('g',"9");
leetComp.put('h',"|-|");
leetComp.put('i',"1");
leetComp.put('j',"j");
leetComp.put('k',"|<");
leetComp.put('l',"L");
leetComp.put('m',"?/\\/\\");
leetComp.put('n',"|\\|");
leetComp.put('o',"O");
leetComp.put('p',"P");
leetComp.put('q',"Q");
leetComp.put('r',"R");
leetComp.put('s',"$");
leetComp.put('t',"7");
leetComp.put('u',"U");
leetComp.put('v',"\\/");
leetComp.put('w',"\\/\\/");
leetComp.put('x',"><");
leetComp.put('y',"'/");
leetComp.put('z',"Z");
//Loop for comparison
for(char key:leetComp.keySet()){
if(key==ch) {
return leetComp.get(key);
}
}
return null;
}

}

Output Screenshot:-

----------------------------------------

Please give me a UPVOTE. Thank you :)


Related Solutions

Write on how 3D printers are being used in the health system
Write on how 3D printers are being used in the health system
The electroscope was a tool used in the early days of classical physics to explore the way in which charges interact, enabling measurement of small forces, and establishing Coulomb's law.
  The electroscope was a tool used in the early days of classical physics to explore the way in which charges interact, enabling measurement of small forces, and establishing Coulomb's law. If there are two balls each the same mass hanging by threads of the same length and equally charged then they repel one another and push apart. Gravity pulls them back toward one another. Let each ball have a mass of 2 g (0.002 kg), and be hanging from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT