Skip to content

Instantly share code, notes, and snippets.

@aokolovskis
Last active August 29, 2015 14:11
Show Gist options
  • Save aokolovskis/8631e6929a5f240def77 to your computer and use it in GitHub Desktop.
Save aokolovskis/8631e6929a5f240def77 to your computer and use it in GitHub Desktop.
Little Java class, to generate leet speak content. This may be used for passwords generation.
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Scanner;
public class LeetSeek {
/**
* @param args
* Terminate with CTRL-D
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
LeetSeek l = new LeetSeek();
while (scan.hasNextLine()){
String s = scan.nextLine();
System.out.println(l.getLeet(s));
}
scan.close();
}
public HashMap<String, String[]> substitutions = new HashMap<String, String[]>() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
put("A",
new String[] { "4", "@", "/\\", "/-\\", "?", "^", "α", "λ" });
put("B",
new String[] { "8", "|3", "ß", "l³", "|>", "13", "I3", "J3" });
put("C", new String[] { "(", "[", "<", "©", "¢" });
put("D", new String[] { "|)", "|]", "Ð", "đ", "1)" });
put("E", new String[] { "3", "€", "&", "£", "ε" });
put("F", new String[] { "|=", "PH", "|*|-|", "|\"", "ƒ", "l²" });
put("G", new String[] { "6", "&, 9" });
put("H",
new String[] { "4", "|-|", "#", "}{", "]-[", "/-/", ")-(" });
put("I", new String[] { "!", "1", "|", "][", "ỉ" });
put("J", new String[] { "_|", "¿" });
put("K", new String[] { "|<", "|{", "|(", "X" });
put("L", new String[] { "1", "|_", "£", "|", "][_" });
put("M", new String[] { "/\\/\\", "/v\\", "|V|", "]V[", "|\\/|",
"AA", "[]V[]", "|11", "/|\\", "^^", "(V)", "|Y|", "!\\/!" });
put("N", new String[] { "|\\|", "/\\/", "/V", "|V", "/\\/", "|1",
"2", "?", "(\\)", "11", "r", "!\\!" });
put("O", new String[] { "0", "9", "()", "[]", "*", "°", "<>", "ø",
"{[]}" });
put("P", new String[] { "9", "|°", "p", "|>", "|*", "[]D", "][D",
"|²", "|?", "|D" });
put("Q", new String[] { "0_", "0," });
put("R", new String[] { "2", "|2", "1²", "®", "?", "я", "12", ".-" });
put("S", new String[] { "5", "$", "§", "?", "ŝ", "ş" });
put("T", new String[] { "7", "+", "†", "']['", "|" });
put("U", new String[] { "|_|", "µ", "[_]", "v" });
put("V", new String[] { "\\/", "|/", "\\|", "\\'" });
put("W", new String[] { "\\/\\/", "VV", "\\A/", "\\'", "uu",
"\\^/", "\\|/", "uJ" });
put("X", new String[] { "><", ")(", "}{", "%", "?", "×", "][" });
put("Y", new String[] { "`/", "°/", "¥" });
put("Z", new String[] { "z", "2", "\"/_" });
put("Ä", new String[] { "43", "°A°", "°4°" });
put("Ö", new String[] { "03", "°O°" });
put("Ü", new String[] { "|_|3", "°U°" });
}
};
String getLeet(String replace) {
Random r = new Random();
String input = replace.toUpperCase();
HashMap<String, String> current_substitutions = new HashMap<String, String>();
for (Entry<String, String[]> e : substitutions.entrySet()) {
current_substitutions
.put(e.getKey(),
e.getValue()[r.nextInt(e.getValue().length)]);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
String subs = current_substitutions.get(input.substring(i, i + 1));
if (subs != null && r.nextBoolean()) {
sb.append(subs);
} else sb.append(r.nextBoolean()?input.substring(i,i+1):replace.substring(i,i+1));
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment