diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 094560d..3b80127 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'me.trouper' -version '0.0.1' +version '0.0.2' repositories { mavenCentral() diff --git a/src/main/java/me/trouper/Data/MC2Ansi.java b/src/main/java/me/trouper/Data/MC2Ansi.java new file mode 100644 index 0000000..8590968 --- /dev/null +++ b/src/main/java/me/trouper/Data/MC2Ansi.java @@ -0,0 +1,49 @@ +package me.trouper.Data; + +import java.util.HashMap; +import java.util.Map; + +public class MC2Ansi { + public static Map getColors() { + Map minecraftToAnsi = new HashMap<>(); + minecraftToAnsi.put("<&0>", "\u001B[0;30m"); + minecraftToAnsi.put("<&1>", "\u001B[0;34m"); + minecraftToAnsi.put("<&2>", "\u001B[0;32m"); + minecraftToAnsi.put("<&3>", "\u001B[0;36m"); + minecraftToAnsi.put("<&4>", "\u001B[0;31m"); + minecraftToAnsi.put("<&5>", "\u001B[0;35m"); + minecraftToAnsi.put("<&6>", "\u001B[0;33m"); + minecraftToAnsi.put("<&7>", "\u001B[0;37m"); + minecraftToAnsi.put("<&8>", "\u001B[1;30m"); + minecraftToAnsi.put("<&9>", "\u001B[1;34m"); + minecraftToAnsi.put("<&a>", "\u001B[1;32m"); + minecraftToAnsi.put("<&b>", "\u001B[1;36m"); + minecraftToAnsi.put("<&c>", "\u001B[1;31m"); + minecraftToAnsi.put("<&d>", "\u001B[1;35m"); + minecraftToAnsi.put("<&e>", "\u001B[1;33m"); + minecraftToAnsi.put("<&f>", "\u001B[1;37m"); + minecraftToAnsi.put("<&r>", "\u001B[0m"); + return minecraftToAnsi; + } + public static Map getBackgrounds() { + Map minecraftToAnsiBG = new HashMap<>(); + minecraftToAnsiBG.put("<&0h>", "\u001B[40m"); + minecraftToAnsiBG.put("<&1h>", "\u001B[44m"); + minecraftToAnsiBG.put("<&2h>", "\u001B[42m"); + minecraftToAnsiBG.put("<&3h>", "\u001B[46m"); + minecraftToAnsiBG.put("<&4h>", "\u001B[41m"); + minecraftToAnsiBG.put("<&5h>", "\u001B[45m"); + minecraftToAnsiBG.put("<&6h>", "\u001B[43m"); + minecraftToAnsiBG.put("<&7h>", "\u001B[47m"); + minecraftToAnsiBG.put("<&8h>", "\u001B[40;1m"); + minecraftToAnsiBG.put("<&9h>", "\u001B[44;1m"); + minecraftToAnsiBG.put("<&ah>", "\u001B[42;1m"); + minecraftToAnsiBG.put("<&bh>", "\u001B[46;1m"); + minecraftToAnsiBG.put("<&ch>", "\u001B[41;1m"); + minecraftToAnsiBG.put("<&dh>", "\u001B[45;1m"); + minecraftToAnsiBG.put("<&eh>", "\u001B[43;1m"); + minecraftToAnsiBG.put("<&fh>", "\u001B[47;1m"); + return minecraftToAnsiBG; + } + +} diff --git a/src/main/java/me/trouper/Functions/Complexers.java b/src/main/java/me/trouper/Functions/Complexers.java index 8c1ceb3..1d573e1 100644 --- a/src/main/java/me/trouper/Functions/Complexers.java +++ b/src/main/java/me/trouper/Functions/Complexers.java @@ -9,7 +9,7 @@ public class Complexers { Random random = new Random(); int factor = random.nextInt(9)+1; int doubled = i * factor; - String result = "(" + doubled + "/" + factor + ")"; + String result = "<&f>(<&r><&e>" + doubled + "<&b>/<&r><&e>" + factor + "<&f>)<&r>"; if (eval(result) == i) { return result; @@ -17,24 +17,10 @@ public class Complexers { return "(" + i + ")"; } - public static String multiply(int i, int factor) { - String result = "(" + i + "*" + factor + ")"; - if (eval(result) == i * factor) { - return result; - } - return "(" + i + ")"; - } - public static String power(int i, int exp) { - String result = "(" + i + "^" + exp + ")"; - if (eval(result) == Math.pow(i,exp)) { - return result; - } - return "(" + i + ")"; - } - public static String root(int i) { int squared = (int) Math.pow(i,2); - String result = "sqrt(" + squared + ")"; + String result = "<&9>sqrt<&r><&f>(<&r><&e>" + squared + "<&f>)<&r>"; + if (eval(result) == i){ return result; } diff --git a/src/main/java/me/trouper/Functions/Eval.java b/src/main/java/me/trouper/Functions/Eval.java index d35bd48..7d55f66 100644 --- a/src/main/java/me/trouper/Functions/Eval.java +++ b/src/main/java/me/trouper/Functions/Eval.java @@ -1,11 +1,14 @@ package me.trouper.Functions; +import me.trouper.Utils.Utils; import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; public class Eval { public static double eval(String expression) { - Expression exp = new ExpressionBuilder(expression).build(); + final String cleaned = Utils.removeColors(expression); + Utils.verbose("Evaluating Expression: " + cleaned); + Expression exp = new ExpressionBuilder(cleaned).build(); return exp.evaluate(); } public static boolean isPerfectSquare(int num) { diff --git a/src/main/java/me/trouper/Functions/Increasers.java b/src/main/java/me/trouper/Functions/Increasers.java new file mode 100644 index 0000000..bf1dfb8 --- /dev/null +++ b/src/main/java/me/trouper/Functions/Increasers.java @@ -0,0 +1,22 @@ +package me.trouper.Functions; + +import static me.trouper.Functions.Eval.eval; + +public class Increasers { + public static String multiply(int i, int factor) { + String result = "<&7>(<&r><&2>" + i + "<&b>*<&r><&2>" + factor + "<&7>)<&r>"; + + if (eval(result) == i * factor) { + return result; + } + return "(" + i + ")"; + } + public static String power(int i, int exp) { + String result = "<&7>(<&r><&2>" + i + "<&b>^<&r><&2>" + exp + "<&7>)<&r>"; + + if (eval(result) == Math.pow(i,exp)) { + return result; + } + return "(" + i + ")"; + } +} diff --git a/src/main/java/me/trouper/Functions/Obf.java b/src/main/java/me/trouper/Functions/Obf.java new file mode 100644 index 0000000..7e929c6 --- /dev/null +++ b/src/main/java/me/trouper/Functions/Obf.java @@ -0,0 +1,123 @@ +package me.trouper.Functions; + +import java.util.Random; + +import static me.trouper.Functions.Eval.*; +import static me.trouper.Functions.Eval.eval; +import static me.trouper.Utils.Utils.removeColors; +import static me.trouper.Utils.Utils.verbose; + +public class Obf { + public static String obfInt(int target, boolean deep) { + if (deep) System.out.println("Deep Obfuscation is coming soon!"); + StringBuilder expression = new StringBuilder(); + + Random random = new Random(); + + int initializer = random.nextInt(9)+1; + verbose("Initializing Expression: " + initializer); + expression.append("<&dh><&f>").append(initializer).append("<&r>"); + + int cubeCount = 0; + int factorCount = 0; + int addCount = 0; + int subCount = 0; + int rootCount = 0; + int divideCount = 0; + int perfectCount = 0; + int total = 0; + + while (eval(expression.toString()) != target) { + total++; + int eval = (int) eval(expression.toString()); + int ri = random.nextInt(9)+1; + int op = random.nextInt(2); + boolean mult = false; + + if (!isInt(eval(expression.toString()))) { + System.out.println("Something went horribly wrong, Here is the relevant info." + + "\nEvaluation: " + eval(expression.toString()) + + "\nRandom Pick: " + ri + + "\nOperation: " + op + + "\nCaught at: \n" + removeColors(expression.toString())); + break; + } + + verbose("Random: " + ri); + verbose("Current: " + eval(expression.toString())); + + if (isPerfectSquare(eval) && eval != 1) { + perfectCount++; + verbose("PERFECT SQUARE TIME! (" + perfectCount+ ")"); + expression.insert(0,"<&eh><&b>sqrt(<&r>").append("<&eh><&b>)<&r>"); + eval = (int) eval(expression.toString()); + } + if (target - eval > 4069) { + mult = true; + cubeCount++; + verbose("Large than (" + cubeCount + ")"); + final String toAdd = Increasers.power(ri,3); + expression.append("<&b>+<&r><&a>").append(toAdd).append("<&r>"); + } else if (target - eval > 1048) { + mult = true; + cubeCount++; + verbose("Large than (" + cubeCount + ")"); + final String toAdd = Increasers.power(ri,2); + expression.append("<&b>+<&r><&a>").append(toAdd).append("<&r>"); + } else if (target - eval > 128) { + factorCount++; + verbose("Big than (" + factorCount + ")"); + final String toAdd = Increasers.multiply(ri,9); + expression.append("<&b>+<&r><&a>").append(toAdd).append("<&r>"); + continue; + } + + if (eval < target) { + addCount++; + if (op == 0) { + divideCount++; + } else { + rootCount++; + } + + final String toAdd = (op == 0) ? Complexers.divide(ri) : Complexers.root(ri); + + expression.append((mult) ? "<&b>*<&r>" : "<&b>+<&r><&e>").append(toAdd).append("<&r>"); + verbose("Less than (" + addCount + ")"); + } + + if (eval > target) { + subCount++; + if (op == 0) { + divideCount++; + } else { + rootCount++; + } + + final String toAdd = (op == 0) ? Complexers.divide(ri) : Complexers.root(ri); + /* + String colored = Utils.highlightReg(toAdd); + if (deep) { + colored = Utils.highlightDeep(toAdd); + }*/ + expression.insert(0,"<&c>(<&r>").append("<&c>)<&r>"); + expression.append("<&b>-<&r><&e>").append(toAdd).append("<&r>"); + verbose("Greater than (" + subCount + ")"); + } + } + + verbose("Broke out of loop. Value: " + eval(expression.toString())); + verbose("Expression: " + expression); + verbose("Expression (Cleaned): " + removeColors(expression.toString())); + System.out.println("\n\n\n\nStatistics: " + + "\nCubes: " + cubeCount + + "\nFactors: " + factorCount + + "\nAdditions: " + addCount + + "\nSubtractions: " + subCount + + "\nRoots Taken: " + rootCount + + "\nDivisors: " + divideCount + + "\nPerfect Squares Found: " + perfectCount + + "\nTotal steps taken: " + total); + return expression.toString(); + } +} diff --git a/src/main/java/me/trouper/Main.java b/src/main/java/me/trouper/Main.java index 89af6b0..ae5d42c 100644 --- a/src/main/java/me/trouper/Main.java +++ b/src/main/java/me/trouper/Main.java @@ -1,29 +1,55 @@ package me.trouper; -import me.trouper.Functions.Complexers; +import me.trouper.Functions.Obf; +import me.trouper.Utils.Timer; +import me.trouper.Utils.Utils; -import java.util.Random; import java.util.Scanner; -import static me.trouper.Functions.Eval.*; +import static me.trouper.Functions.Eval.eval; +import static me.trouper.Utils.Utils.removeColors; public class Main { - + public static boolean verbose; + public static boolean deep; + public static boolean color; + public static boolean printHelp; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); + boolean doCopy = false; + + + for (String arg : args) { + switch (arg) { + case "--copy", "-c" -> doCopy = true; + case "--verbose", "-v" -> verbose = true; + case "--deep", "-d" -> deep = true; + case "--color", "-rgb" -> color = true; + case "--help", "--h", "-h" -> printHelp = true; + } + } + + if (printHelp) Utils.printHelp(); + if (color) Utils.printColorKey(); while (true) { System.out.print("Enter Target Integer: "); if (scanner.hasNextInt()) { int target = scanner.nextInt(); - String expression = obfInt(target); - double output = eval(expression); + Timer obfTimer = Timer.start(); + String expression = Obf.obfInt(target, deep); + long obfTime = obfTimer.end().timePassed(); + double output = eval(removeColors(expression)); System.out.println("\nTarget Integer: " + target); + System.out.println("\nElapsed Time: " + obfTime + "ms"); + + if (output == target) { - System.out.println("Expression Verified Correct: \n" + expression); + System.out.println(Utils.activateColors("<&2h><&f>Expression Correct<&r>\n\n" + ((color) ? expression : removeColors(expression)))); + if (doCopy) Utils.copyToClip(removeColors(expression)); } else { - System.out.println("!!!! INCORRECT !!!! \n" + expression); + System.out.println(Utils.activateColors("<&ch><&0>!!!! INCORRECT !!!!<&r>\n\n" + ((color) ? expression : removeColors(expression)))); } } else { System.out.println("Exiting the program."); @@ -33,95 +59,4 @@ public class Main { scanner.close(); } - - public static String obfInt(int target) { - StringBuilder expression = new StringBuilder(); - Random random = new Random(); - - int initializer = random.nextInt(9)+1; - System.out.println("Initializing Expression: " + initializer); - expression.append(initializer); - - int cubeCount = 0; - int factorCount = 0; - int addCount = 0; - int subCount = 0; - int rootCount = 0; - int divideCount = 0; - int perfectCount = 0; - int total = 0; - - while (eval(expression.toString()) != target) { - total++; - int eval = (int) eval(expression.toString()); - int ri = random.nextInt(9)+1; - int op = random.nextInt(2); - - if (!isInt(eval(expression.toString()))) { - System.out.println("Something went horribly wrong, Here is the relevant info." + - "\nEvaluation: " + eval(expression.toString()) + - "\nRandom Pick: " + ri + - "\nOperation: " + op + - "\nCaught at: \n" + expression); - break; - } - - System.out.println("Random: " + ri); - System.out.println("Current: " + eval(expression.toString())); - - if (isPerfectSquare(eval)) { - perfectCount++; - System.out.println("PERFECT SQUARE TIME! (" + perfectCount+ ")"); - expression.insert(0,"sqrt(").append(")"); - eval = (int) eval(expression.toString()); - } - - if (target - eval > 1000) { - cubeCount++; - System.out.println("Enormous than (" + cubeCount + ")"); - expression.append("+").append(Complexers.power(ri,3)); - } else if (target - eval > 100) { - factorCount++; - System.out.println("Large than (" + factorCount + ")"); - expression.append("+").append(Complexers.multiply(ri,10)); - } - - if (eval < target) { - addCount++; - if (op == 0) { - divideCount++; - } else { - rootCount++; - } - expression.append("+").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri)); - System.out.println("Less than (" + addCount + ")"); - } - - if (eval > target) { - subCount++; - if (op == 0) { - divideCount++; - } else { - rootCount++; - } - expression.insert(0,"(").append(")"); - - expression.append("-").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri)); - System.out.println("Greater than (" + subCount + ")"); - } - } - - System.out.println("Broke out of loop. Value: " + eval(expression.toString())); - System.out.println("Expression: " + expression.toString()); - System.out.println("Statistics: " + - "\nCubes: " + cubeCount + - "\nFactors: " + factorCount + - "\nAdditions: " + addCount + - "\nSubtractions: " + subCount + - "\nRoots Taken: " + rootCount + - "\nDivisors " + divideCount + - "\nPerfect Squares Found: " + perfectCount + - "\nTotal steps taken: " + total); - return expression.toString(); - } } diff --git a/src/main/java/me/trouper/Utils/Timer.java b/src/main/java/me/trouper/Utils/Timer.java new file mode 100644 index 0000000..2d59113 --- /dev/null +++ b/src/main/java/me/trouper/Utils/Timer.java @@ -0,0 +1,93 @@ +package me.trouper.Utils; + +public class Timer { + + /* Timer Curtosy of ImproperIssues + * https://your-mom-is-so-fat-we-couldnt-fit-her-in-this-doma.in/tugdkppa.png + * Yes, I got permission to use it this time! */ + + public static final long MILLIS_IN_SECOND = 1000L; + public static final long MILLIS_IN_MINUTE = MILLIS_IN_SECOND * 60L; + public static final long MILLIS_IN_HOUR = MILLIS_IN_MINUTE * 60L; + public static final long MILLIS_IN_DAY = MILLIS_IN_HOUR * 24L; + private long start; + + private Timer() { + this.start = System.currentTimeMillis(); + } + + public static Timer start() { + return new Timer(); + } + + public static End zero() { + return new End(0); + } + + public End end() { + return new End(start); + } + + + public static class End { + + private final long start; + private final long end; + + private End(long start) { + this.end = System.currentTimeMillis(); + this.start = start; + } + + public long timePassed() { + return end - start; + } + + public String getStamp(boolean day, boolean hr, boolean min, boolean sec, boolean ms) { + long time = timePassed(); + String stamp = ""; + + if (day) { + long l = (long)Math.floor((double)time / (double)MILLIS_IN_DAY); + time -= l * MILLIS_IN_DAY; + if (l > 0L) stamp += l + "d"; + } + if (hr) { + long l = (long)Math.floor((double)time / (double)MILLIS_IN_HOUR); + time -= l * MILLIS_IN_HOUR; + if (l > 0L) stamp += " " + l + "hr"; + } + if (min) { + long l = (long)Math.floor((double)time / (double)MILLIS_IN_MINUTE); + time -= l * MILLIS_IN_MINUTE; + if (l > 0L) stamp += " " + l + "min"; + } + if (sec) { + long l = (long)Math.floor((double)time / (double)MILLIS_IN_SECOND); + time -= l * MILLIS_IN_SECOND; + if (l > 0L) stamp += " " + l + "sec"; + } + if (ms) { + if (time > 0L) stamp += " " + time + "ms"; + } + + return stamp.trim(); + } + + public String getStampStandard() { + return getStamp(false, true, true, false, false); + } + + public String getStampLogger() { + return getStamp(false, true, true, true, false); + } + + public String getStampPrecise() { + return getStamp(false, false, true, true, true); + } + + public String getStampFull() { + return getStamp(true, true, true, true, true); + } + } +} diff --git a/src/main/java/me/trouper/Utils/Utils.java b/src/main/java/me/trouper/Utils/Utils.java new file mode 100644 index 0000000..e1e7745 --- /dev/null +++ b/src/main/java/me/trouper/Utils/Utils.java @@ -0,0 +1,106 @@ +package me.trouper.Utils; + +import me.trouper.Data.MC2Ansi; +import me.trouper.Main; + +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.util.Map; + +public class Utils { + public static void copyToClip(String text) { + StringSelection parsed = new StringSelection(text); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(parsed,null); + } + public static void verbose(String text) { + if (Main.verbose) System.out.println(text); + } + public static String removeColors(String input) { + return input.replaceAll("<&[0-9a-fr]>|<&[0-9a-frh]h>", ""); + } + public static String activateColors(String input) { + Map minecraftToAnsi = MC2Ansi.getColors(); + + Map minecraftBackgroundsToAnsi = MC2Ansi.getBackgrounds(); + + for (Map.Entry entry : minecraftToAnsi.entrySet()) { + input = input.replace(entry.getKey(), entry.getValue()); + } + + for (Map.Entry entry : minecraftBackgroundsToAnsi.entrySet()) { + input = input.replace(entry.getKey(), entry.getValue()); + } + + input += "\u001B[0m\u001B[49m"; + + return input; + } + + public static void printHelp() { + System.out.println("Usage: java -jar Countroll-.jar [options]"); + System.out.println("Options:"); + System.out.println(" --copy, -c Copy the generated expression to the clipboard"); + System.out.println(" --verbose, -v Enable verbose mode"); + System.out.println(" --deep, -d Enable deep obfuscation (under development)"); + System.out.println(" --color, -rgb Enable colored output"); + System.out.println(" --help, --h, -h Show this help message"); + System.out.println("Note: When using multiple options, separate them with spaces."); + System.exit(0); + } + public static void printColorKey() { + String colorKey = "\nColor Key: " + + "\n<&c>Red Parentheses:<&r> Gets Subtracted" + + "\n<&b><&eh>Blue/Yellow:<&r> Perfect Square" + + "\n<&a>Green:<&r> Increaser" + + "\n<&9>Blue:<&r> Operation" + + "\n<&e>Yellow:<&r> Complexer"; + System.out.println(activateColors(colorKey)); + } + /* + public static String highlightReg(String exp) { + final String result = exp + .replaceAll("\\(", ANSI.WHITE + "(" + ANSI.RESET) + .replaceAll("\\)", ANSI.WHITE + ")" + ANSI.RESET) + .replaceAll("\\*", ANSI.BLUE + "*" + ANSI.RESET) + .replaceAll("/", ANSI.BLUE + "/" + ANSI.RESET) + .replaceAll("\\+", ANSI.BLUE + "+" + ANSI.RESET) + .replaceAll("-", ANSI.BLUE + "-" + ANSI.RESET) + .replaceAll("\\^", ANSI.BLUE + "^" + ANSI.RESET) + .replaceAll("\\d+", ANSI.GREEN + "$0" + ANSI.RESET); + verbose("Attempting Ansi Highlight: " + result); + return result; + } + + public static String highlightDeep(String exp) { + final String result = exp + .replaceAll("\\(", ANSI.CYAN + "*" + ANSI.RESET) + .replaceAll("\\)", ANSI.CYAN + "*" + ANSI.RESET) + .replaceAll("\\*", ANSI.BLUE + "*" + ANSI.RESET) + .replaceAll("/", ANSI.BLUE + "/" + ANSI.RESET) + .replaceAll("\\+", ANSI.BLUE + "+" + ANSI.RESET) + .replaceAll("-", ANSI.BLUE + "-" + ANSI.RESET) + .replaceAll("\\^", ANSI.BLUE + "^" + ANSI.RESET) + .replaceAll("\\d+", ANSI.PURPLE + "$0" + ANSI.RESET); + verbose("Attempting Ansi Highlight (Deep): " + result); + return result; + } + public static String fixAnsi(String input) { + Pattern pattern = Pattern.compile("(\\[\\d+m)"); + Matcher matcher = pattern.matcher(input); + StringBuffer sb = new StringBuffer(); + + while (matcher.find()) { + // Check if the escape code was not properly closed (e.g., missing reset code) + if (input.substring(matcher.start()).indexOf(ANSI.RESET) < 0) { + String escapeCode = matcher.group(1); + // Re-escape the ANSI escape code + matcher.appendReplacement(sb, escapeCode); + } + } + matcher.appendTail(sb); + + return sb.toString(); + }*/ +}