Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Created September 10, 2012 06:48
Show Gist options
  • Save chintanparikh/3689292 to your computer and use it in GitHub Desktop.
Save chintanparikh/3689292 to your computer and use it in GitHub Desktop.
import java.util.*;
/**
* LeetTranslator translates text into leetspeak
*/
public class LeetTranslator {
public static void main(String[] args) {
// Ask the user whether to convert between normal -> leet or leet -> normal
Scanner scan = new Scanner(System.in);
System.out.print("Type N to convert from (N)ormal text to Leetspeak, or L to convert from (L)eetspeak to Normal: ");
String type = scan.nextLine().replace("\n", "").replace("\r", "");
// Create the mapping between normal characters and leet speak
Map<Character, Character> leetMap = new HashMap<Character, Character>();
System.out.println(type == "N");
if(type == "N") {
leetMap.put('a', '@');
leetMap.put('e', '3');
leetMap.put('i', '1');
leetMap.put('s', '5');
leetMap.put('o', '0');
}
else if(type == "L") {
leetMap.put('@', 'a');
leetMap.put('3', 'e');
leetMap.put('5', 's');
leetMap.put('0', 'o');
leetMap.put('1', 'i');
}
// Get the user input
System.out.print("Enter text to translate: ");
String input = scan.nextLine();
String output = input;
// Iterate over leetMap and replace characters in the string
Iterator<Character> leetIterator = leetMap.keySet().iterator();
while(leetIterator.hasNext()) {
Character key = leetIterator.next();
output = output.replace(key, leetMap.get(key));
}
System.out.println(output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment