diff options
-rw-r--r-- | lib/jdtalk/core.d | 93 | ||||
-rw-r--r-- | source/app.d | 16 |
2 files changed, 109 insertions, 0 deletions
diff --git a/lib/jdtalk/core.d b/lib/jdtalk/core.d index 0ed929a..f3023b2 100644 --- a/lib/jdtalk/core.d +++ b/lib/jdtalk/core.d @@ -2,12 +2,14 @@ module jdtalk.core; import std.algorithm; import std.array; +import std.ascii; import std.file; import std.path; import std.process : environment; import std.random; import std.stdio; import std.string; +import std.conv : to; struct dict_t { @@ -35,6 +37,97 @@ string word(string[] arr) { } +string randomCase(string s) { + auto SEED = Random(unpredictableSeed); + string[] arr = s.split(""); + ulong count = arr.length; + for (ulong i = 0; i < count; i++) { + ulong pos = uniform(0, arr.length, SEED); + if (arr[pos].to!char.isWhite) { + i--; + continue; + } + arr[pos] = arr[pos].toUpper; + } + + return arr.join(""); +} + + +string hillCase(string s) { + string[] arr = s.split(""); + for (ulong i = 0; i < arr.length; i++) { + if (i % 2) { + arr[i] = arr[i].toLower; + } + else { + arr[i] = arr[i].toUpper; + } + } + + return arr.join(""); +} + + +string leetSpeak(string s) { + string[dchar] trx = [ + 'a': "4", + 'A': "4", + 'b': "8", + 'B': "8", + 'c': "(", + 'C': "(", + 'd': ")", + 'D': ")", + 'e': "3", + 'E': "3", + 'f': "ƒ", + 'F': "ƒ", + 'g': "6", + 'G': "6", + 'h': "#", + 'H': "#", + 'i': "!", + 'I': "!", + 'j': "]", + 'J': "]", + 'k': "X", + 'K': "X", + 'l': "1", + 'L': "1", + 'm': "|\\/|", + 'M': "|\\/|", + 'n': "|\\|", + 'N': "|\\|", + 'o': "0", + 'O': "0", + 'p': "|*", + 'P': "|*", + 'q': "9", + 'Q': "9", + 'r': "|2", + 'R': "|2", + 's': "$", + 'S': "$", + 't': "7", + 'T': "7", + 'u': "|_|", + 'U': "|_|", + 'v': "\\/", + 'V': "\\/", + 'w': "\\/\\/", + 'W': "\\/\\/", + 'x': "><", + 'X': "><", + 'y': "¥", + 'Y': "¥", + 'z': "2", + 'Z': "2", + ]; + return translate(s, trx); +} + + bool hasWord(string match, string str) { if (str is null) return false; diff --git a/source/app.d b/source/app.d index d5b89ad..387d19d 100644 --- a/source/app.d +++ b/source/app.d @@ -21,6 +21,9 @@ int main(string[] args) long i = 0, limit = 0; bool exactMatch = false; + bool rCase = false; + bool hCase = false; + bool haxor = false; string pattern = null; string dataRoot = absolutePath(getcwd()); @@ -33,6 +36,9 @@ int main(string[] args) "limit|c", format("(default: %d)", limit), &limit, "pattern|p", "Limit output to a root word", &pattern, "exact|e", format("Exact matches only (default: %s)", exactMatch ? "true" : "false"), &exactMatch, + "rcase", format("Randomize case (default: %s)", rCase ? "true" : "false"), &rCase, + "hcase", format("Change every other case (default: %s)", hCase ? "true" : "false"), &hCase, + "leet", format("1337ify output (default: %s)", haxor ? "true" : "false"), &haxor, "dataroot|d", "Path to dictionaries", &dataRoot, ); @@ -66,6 +72,16 @@ int main(string[] args) } } + if (rCase) { + output = randomCase(output); + } + else if (hCase) { + output = hillCase(output); + } + else if (haxor) { + output = leetSpeak(output); + } + writeln(output); if (limit > 0) { |