Skip to content

Instantly share code, notes, and snippets.

@superblaubeere27
Last active July 25, 2019 00:33
Show Gist options
  • Save superblaubeere27/42e253c12a15212fe286480ff7b42026 to your computer and use it in GitHub Desktop.
Save superblaubeere27/42e253c12a15212fe286480ff7b42026 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* @author superblaubeere27, Bon (https://stackoverflow.com/questions/33416987/java-simple-english-to-leet-converter)
*/
public class Leet {
static char leet[] = {'4', '8', '(', ')', '3', '}', '6', '#', '!', ']', 'X', '1', 'M', 'N', '0', '9', 'Q', '2', 'Z', '7', 'M', 'V', 'W', 'X', 'J', 'Z'};
static HashMap<String, String> replace = new HashMap<String, String>();
static {
replace.put("HACKER", "HAX0R");
}
private static String toLeet(String s) {
StringBuilder result = new StringBuilder();
Random rand = new Random();
String str = s.toUpperCase(); // convert all to upper case so that you don't need equalsIgnoreCase()
for (Map.Entry<String, String> stringStringEntry : replace.entrySet()) {
str = str.replace(stringStringEntry.getKey(), stringStringEntry.getValue());
}
for (int i = 0; i < str.length(); ++i) {
char c = str.charAt(i);
if ((c - 'A') < 0 || (c - 'A') > leet.length) {
result.append(c);
continue;
}
result.append(rand.nextBoolean() ? leet[c - 'A'] : Character.toLowerCase(leet[c - 'A'])); // Str.charAt(i) - 'A' this will give you the correct index in leet
}
return result.toString();
}
}
@UnicodeDevelopmentTeam
Copy link

xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment