Cleaned up the main class and finished the config manager

This commit is contained in:
obvWolf
2023-11-07 20:31:53 -06:00
parent 324e11722f
commit 2a31690d61
6 changed files with 184 additions and 119 deletions

View File

@@ -53,6 +53,34 @@ Make sure you have Java 17 or higher installed on your system!
3. Build with gradle `$ ./gradlew build` 3. Build with gradle `$ ./gradlew build`
4. Build will be output to `/Countroll/build/libs` 4. Build will be output to `/Countroll/build/libs`
# Config With Comments
```json
{ // The config is in json, there are no comments allowed in the countroll.json
"doCopy": false, // Automaticaly copying to clipboard
"deep": false, // Deep obfuscation, doubling output size
"verbose.errors": true, // Error printing
"color": true, // Razor Chroma RGB xpressions are outputed
"useRoot": true, // Uses sqrt() function
"verbose.complexers": false, // Shows what the complexers are doing
"show.progress": false, // Shows the current eval as the expression is building
"useDivide": true, // Toggles the divide complexer
"verbose.eval": false, // Shows what the eval function is doing
"verbose.processes": true, // Shows non looping verbose
"printHelp": false, // Prints a help message then exits
"mode": "U", // Switch modes
// U is universal, and will follow all the comlpexer toggles for fully custom setup
// D is duckgroup mode, and will not use lettered functions
// N is numselli mode, and will enable all complexers
"verbose.all": false, // Shows all the verbose
"usePower": true, // Toggles power complexer
"useModDividend": true, // Toggles moduRootDividend complexer (doesnt use letters)
"verbose.utils": false, // Shows what the Utils are doing
"verbose.increasers": false, // Shows what the increasers are doing
"verbose.loops": false // Shows what the loops are doing
}
```
# Up Next # Up Next
Development will continue with the addition of bitwise operations AND (&) and OR (|) Development will continue with the addition of bitwise operations AND (&) and OR (|)
- Both bots support these operators, and it will be in both modes - Both bots support these operators, and it will be in both modes

View File

@@ -10,9 +10,11 @@ import me.trouper.Utils.Verbose;
import java.util.Scanner; import java.util.Scanner;
import static me.trouper.Functions.Eval.eval; import static me.trouper.Functions.Eval.eval;
import static me.trouper.Utils.Utils.copyToClip;
import static me.trouper.Utils.Utils.removeColors; import static me.trouper.Utils.Utils.removeColors;
public class Countroll { public class Countroll {
public static boolean showProgress;
public static boolean doCopy; public static boolean doCopy;
public static boolean deep; public static boolean deep;
public static boolean color; public static boolean color;
@@ -47,10 +49,35 @@ public class Countroll {
errorCount = 0; errorCount = 0;
} }
public static void main(String[] args) { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
ConfigManager.loadConfig(); ConfigManager.loadConfig();
parseCommandLineArguments(args);
Verbose.send("INIT", "Loading config");
Verbose.send("INIT", "Config loaded, mode: " + mode);
if (mode.equals("D")) {
Complexers.useRoot = false;
}
if (mode.equals("TEST")) {
handleTestMode(scanner);
}
if (printHelp) {
Utils.printHelp();
System.exit(0);
}
if (color) {
Utils.printColorKey();
}
handleTargetIntegers(scanner);
scanner.close();
}
private static void parseCommandLineArguments(String[] args) {
for (String arg : args) { for (String arg : args) {
switch (arg) { switch (arg) {
case "--copy", "-c" -> doCopy = true; case "--copy", "-c" -> doCopy = true;
@@ -64,80 +91,92 @@ public class Countroll {
case "--mode=universal", "-m=u" -> mode = "U"; case "--mode=universal", "-m=u" -> mode = "U";
} }
} }
}
Verbose.send("INIT","Loading config"); private static void handleTestMode(Scanner scanner) {
while (true) {
System.out.print("Enter an expression (or 'exit' to exit): ");
String userInput = scanner.next();
Verbose.send("INIT","Config loaded, mode: " + mode); if (userInput.equals("exit")) {
Complexers.useRoot = true; System.exit(0);
Complexers.usePower = true; }
Complexers.useDivide = true;
Complexers.useRDivisor = true;
Complexers.useRDividend = true;
if (mode.equals("D")) Complexers.useRoot = false;
if (mode.equals("TEST")) { try {
while (true) { double result = eval(userInput);
System.out.print("Enter an expression (or 'exit' to exit): "); System.out.println("Result: " + result);
String userInput = scanner.next(); } catch (Exception e) {
System.out.println("Error: " + e.getMessage());
if (userInput.equals("exit")) {
System.exit(0);
}
try {
double result = eval(userInput);
System.out.println("Result: " + result);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
} }
} }
}
if (printHelp) Utils.printHelp(); private static void handleTargetIntegers(Scanner scanner) {
if (color) Utils.printColorKey();
while (true) { while (true) {
System.out.print("Enter Target Integer: "); System.out.print("Enter Target Integer: ");
if (scanner.hasNextInt()) { if (scanner.hasNextInt()) {
int target = scanner.nextInt(); int target = scanner.nextInt();
Timer obfTimer = Timer.start(); Timer obfTimer = Timer.start();
String expression = null; String expression = Obf.obfInt(target);
expression = Obf.obfIntN(target,deep);
long obfTime = obfTimer.end().timePassed(); long obfTime = obfTimer.end().timePassed();
double output = eval(removeColors(expression)); double output = eval(removeColors(expression));
System.out.println("\nStatistics" + printStatistics(obfTime);
"\nErrors: " + errorCount + printReport(target,expression,output);
"\nExponents: " + expCount + if (doCopy) copyToClip(removeColors(expression));
"\nFactors: " + factorCount +
"\nAdditions: " + addCount +
"\nSubtractions: " + subCount +
"\nDivisors: " + divideCount +
"\nPowers: " + powerCount +
"\nmRootDividends: " + rDividendCount +
"\nmRootDivisors: " + rDivisorCount +
"\nRoots Taken: " + rootCount +
"\nPerfect Squares Found: " + perfectCount +
"\nTotal steps taken: " + total);
System.out.println("\nElapsed Time: " + obfTime + "ms");
System.out.println("\nTarget Integer: " + target);
if (output == target) {
System.out.println(Utils.activateColors("<&2h><&f>Expression Correct<&r>\n\n" + ((color) ? expression : removeColors(expression))));
if (doCopy) Utils.copyToClip(removeColors(expression));
clearStats();
} else {
System.out.println(Utils.activateColors("<&ch><&0>!!!! INCORRECT !!!!<&r>\n\n" + ((color) ? expression : removeColors(expression))));
}
} else { } else {
System.out.println("Exiting the program."); System.out.println("Exiting the program.");
break; break;
} }
} }
}
private static void printReport(int target, String expression, double output) {
String report;
if (target == output) {
report = String.format("""
╔═══════[ Report ]═════════
║ Target Integer: %d
║ Final Result: %s <&ah><&b>✔<&r>
║ Expression Length: %s
╚══════════════════════════
scanner.close(); >> %s
""",target,output,expression.length(),expression);
} else {
report = String.format("""
╔═══════[ Report ]═════════
║ Target Integer: %d
║ Final Result: %s <&ch><&e>❌<&r>
║ Expression Length: %s
╚══════════════════════════
>> %s
""",target,output,expression.length(),expression);
}
System.out.println((color) ? Utils.activateColors(report) : removeColors(report));
} }
private static void printStatistics(long time) {
String statistics = String.format("""
╔═══════[ Statistics ]═════════
║ Exponents: %d
║ Factors: %d
║ Additions: %d
║ Subtractions: %d
║ Divisors: %d
║ Powers: %d
║ mRootDividends: %d
║ Roots Taken: %d
║ Perfect Squares Found: %d
║ Errors: %d
╠══════════════════════════════
║ Total steps taken: %d
║ Elapsed Time: %d
╚══════════════════════════════
""", expCount, factorCount, addCount, subCount, divideCount, powerCount, rDividendCount, rootCount, perfectCount, errorCount, total, time);
System.out.println(statistics);
}
} }

View File

@@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException; import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import me.trouper.Countroll; import me.trouper.Countroll;
import me.trouper.Functions.Complexers;
import me.trouper.Utils.Verbose; import me.trouper.Utils.Verbose;
import java.io.*; import java.io.*;
@@ -23,7 +24,7 @@ public class ConfigManager {
try (Reader reader = new FileReader(configFile)) { try (Reader reader = new FileReader(configFile)) {
Gson gson = new Gson(); Gson gson = new Gson();
Map<String, Object> config = gson.fromJson(reader, HashMap.class); Map<String, Object> config = gson.fromJson(reader, HashMap.class);
setMainClassVariables(config); getConfig(config);
} catch (JsonSyntaxException | JsonIOException | IOException e) { } catch (JsonSyntaxException | JsonIOException | IOException e) {
e.printStackTrace(); e.printStackTrace();
generateDefaultConfig(); generateDefaultConfig();
@@ -33,11 +34,16 @@ public class ConfigManager {
private static void generateDefaultConfig() { private static void generateDefaultConfig() {
Map<String, Object> defaultConfig = new HashMap<>(); Map<String, Object> defaultConfig = new HashMap<>();
defaultConfig.put("useDivide", true);
defaultConfig.put("usePower", true);
defaultConfig.put("useRoot", true);
defaultConfig.put("useModDividend", true);
defaultConfig.put("doCopy", false); defaultConfig.put("doCopy", false);
defaultConfig.put("deep", false); defaultConfig.put("deep", false);
defaultConfig.put("color", false); defaultConfig.put("color", true);
defaultConfig.put("printHelp", false); defaultConfig.put("printHelp", false);
defaultConfig.put("mode", "N"); defaultConfig.put("mode", "U");
defaultConfig.put("show.progress", false);
defaultConfig.put("verbose.all",false); defaultConfig.put("verbose.all",false);
defaultConfig.put("verbose.processes",true); defaultConfig.put("verbose.processes",true);
defaultConfig.put("verbose.loops",false); defaultConfig.put("verbose.loops",false);
@@ -53,11 +59,16 @@ public class ConfigManager {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
setMainClassVariables(defaultConfig); getConfig(defaultConfig);
} }
private static void setMainClassVariables(Map<String, Object> config) { private static void getConfig(Map<String, Object> config) {
Verbose.send("INIT", "Loading main class variables"); Verbose.send("INIT", "Loading main class variables");
Complexers.useDivide = (boolean) config.get("useDivide");
Complexers.usePower = (boolean) config.get("usePower");
Complexers.useRoot = (boolean) config.get("useRoot");
Complexers.useRDividend = (boolean) config.get("useModDividend");
Countroll.showProgress = (boolean) config.get("show.progress");
Countroll.doCopy = (boolean) config.get("doCopy"); Countroll.doCopy = (boolean) config.get("doCopy");
Countroll.deep = (boolean) config.get("deep"); Countroll.deep = (boolean) config.get("deep");
Countroll.color = (boolean) config.get("color"); Countroll.color = (boolean) config.get("color");

View File

@@ -15,7 +15,6 @@ public class Complexers {
public static boolean usePower; public static boolean usePower;
public static boolean useRoot; public static boolean useRoot;
public static boolean useRDividend; public static boolean useRDividend;
public static boolean useRDivisor;
public static String pickComplexer() { public static String pickComplexer() {
List<String> enabledComplexers = new ArrayList<>(); List<String> enabledComplexers = new ArrayList<>();
@@ -24,7 +23,6 @@ public class Complexers {
if (usePower) enabledComplexers.add("power"); if (usePower) enabledComplexers.add("power");
if (useRoot) enabledComplexers.add("root"); if (useRoot) enabledComplexers.add("root");
if (useRDividend) enabledComplexers.add("mrDividend"); if (useRDividend) enabledComplexers.add("mrDividend");
if (useRDivisor) enabledComplexers.add("mrDivisor");
Collections.shuffle(enabledComplexers); Collections.shuffle(enabledComplexers);
if (!enabledComplexers.isEmpty()) { if (!enabledComplexers.isEmpty()) {
@@ -41,7 +39,9 @@ public class Complexers {
return divide(i,deep); return divide(i,deep);
} }
case "power" -> { case "power" -> {
if (!isPerfectSquare(i)) return complex(i,deep); if (!isPerfectSquare(i)) {
return divide(i,deep);
}
return power(i,deep); return power(i,deep);
} }
case "root" -> { case "root" -> {
@@ -50,9 +50,6 @@ public class Complexers {
case "mrDividend" -> { case "mrDividend" -> {
return mRootDividend(i,deep); return mRootDividend(i,deep);
} }
case "mrDivisor" -> {
return mRootDivisor(i,false);
}
default -> { default -> {
return divide(i,false); return divide(i,false);
} }
@@ -118,32 +115,6 @@ public class Complexers {
return (eval(result) == i) ? result : "<&ch>(" + i + ")<&r>"; return (eval(result) == i) ? result : "<&ch>(" + i + ")<&r>";
} }
/**
* Uses modulus (ri%divisor)=i
* @param i Modulus to return
* @return Colored string
*/
public static String mRootDivisor(int i, boolean deep) {
Verbose.send("COMP", "Running mrDivisor Complexer, I:" + i + " Deep: " + deep);
Countroll.rDivisorCount++;
Random random = new Random();
int dividend = random.nextInt(9)+random.nextInt(48)+1+i;
int divisor = Utils.moduRootDivisor(dividend,i);
String result = "<&r><&f>(<&e>" + dividend + "<&b>%<&e>" + divisor + "<&f>)<&r>";
if (deep) {
result = "<&r><&7>(<&d>" + complex(dividend,false) + "<&b>%<&d>" + complex(divisor,false) + "<&7>)<&r>";
}
Verbose.send("COMP","<&dh><&b>mRootDivisor has ran!<&r>" +
"\nWanted: " + i +
"\nDivisor: " + divisor +
"\nDividend: " + dividend +
"\nCheck: " + dividend + "%" + divisor + "=" + i +
"\nResult: " + result);
if (eval(result) != i) Verbose.send("ERR","<&ch>Failed to mRootDivisor<&r> " + i + ", Attempted: " + result + "=" + eval(result));
return (eval(result) == i) ? result : mRootDividend(i,false);
}
/** /**
* Uses modulus (dividend%ri)=i * Uses modulus (dividend%ri)=i
* @param i Modulus to return * @param i Modulus to return

View File

@@ -14,43 +14,56 @@ import static me.trouper.Functions.Eval.isPerfectSquare;
public class Increasers { public class Increasers {
public static String increase(int current, int target, int i, boolean deep) { public static String increase(int current, int target, int i, boolean deep) {
if (target - current > 64000) {
if (target - current > 4069) { Countroll.expCount++;
return power(i,10,deep); return Increasers.power(i,4,deep);
} else if (target - current > 10000000) { } else if (target - current > 4069) {
return power(i,8,deep); Countroll.expCount++;
} else if (target - current > 1000000) { return Increasers.power(i,3,deep);
return power(i,6,deep); } else if (target - current > 1048) {
} else if (target - current > 100000) { Countroll.expCount++;
return power(i,4,deep); return Increasers.power(i,2,deep);
} else if (target - current > 10000) { } else if (target - current > 128) {
return power(i,3,deep); Countroll.factorCount++;
} else if (target - current > 1000) { return Increasers.multiply(i,9,deep);
return power(i,2,deep);
} else if (target - current > 100) {
return multiply(i,9,deep);
} else { } else {
return multiply(i,2,deep); return multiply(i,2,deep);
} }
} }
public static String multiply(int i, int factor, boolean deep) { public static String multiply(int i, int factor, boolean deep) {
Countroll.factorCount++; Countroll.factorCount++;
String result = "<&7>(<&r><&2>" + i + "<&b>*<&r><&2>" + factor + "<&7>)<&r>"; String result;
if (deep) { if (deep) {
result = "<&7>(<&r><&2>" + (Complexers.complex(i,true)) + "<&b>*<&r><&2>" + Complexers.complex(i,true) + "<&7>)<&r>"; result = "<&7>(<&r><&2>" + (Complexers.complex(i,true)) + "<&b>*<&r><&2>" + Complexers.complex(i,true) + "<&7>)<&r>";
if (eval(result) == i * factor) return result;
} }
if (!(eval(result) == i * factor)) Verbose.send("ERR", "Failed multiply increaser!");
return eval(result) == i * factor ? result : "(" + i + ")"; result = "<&7>(<&r><&2>" + i + "<&b>*<&r><&2>" + factor + "<&7>)<&r>";
double calc = eval(result);
if (!(calc == Math.multiplyExact(i,factor))) Verbose.send("ERR", "Failed multiply increaser! " +
"\nAttempted expression: " + result +
"\nTarget: " + i +
"\nCalc: " + calc);
return calc == i * factor ? result : "(" + i + ")";
} }
public static String power(int i, int exp, boolean deep) { public static String power(int i, int exp, boolean deep) {
Countroll.powerCount++; Countroll.powerCount++;
String result = "<&7>(<&r><&2>" + i + "<&b>^<&r><&2>" + exp + "<&7>)<&r>"; String result;
if (deep) { if (deep) {
result = "<&7>(<&r><&2>" + Complexers.complex(i,true) + "<&b>^<&r><&2>" + Complexers.complex(i,true) + "<&7>)<&r>"; result = "<&7>(<&r><&2>" + Complexers.complex(i,true) + "<&b>^<&r><&2>" + Complexers.complex(i,true) + "<&7>)<&r>";
if (eval(result) == Math.pow(i,exp)) return result;
} }
if (!(eval(result) == Math.pow(i,exp))) Verbose.send("ERR", "Failed power increaser!");
return eval(result) == Math.pow(i,exp) ? result : "(" + i + ")"; result = "<&7>(<&r><&2>" + i + "<&b>^<&r><&2>" + exp + "<&7>)<&r>";
double calc = eval(result);
if (!(calc == Math.pow(i,exp))) Verbose.send("ERR", "Failed multiply increaser! " +
"\nAttempted expression: " + result +
"\nTarget: " + i +
"\nCalc: " + calc);
return calc == Math.pow(i,exp) ? result : "(" + i + ")";
} }
} }

View File

@@ -23,11 +23,12 @@ public class Obf {
// MAIN LOOP // MAIN LOOP
Verbose.send("PROC", "Beginning Main Loop: "); Verbose.send("PROC", "Beginning Main Loop: ");
while (eval(expression.toString()) != target) { while (eval(expression.toString()) != target) {
Countroll.total++; Countroll.total++;
int current = (int) eval(expression.toString()); int current = (int) eval(expression.toString());
int ri = rand.nextInt(9)+1; int ri = rand.nextInt(9)+1;
if (Countroll.showProgress) System.out.println("Current Evaluation: " + current);
// Checking for it still being a whole number
if (!isInt(eval(expression.toString()))) { if (!isInt(eval(expression.toString()))) {
System.out.println("Something went horribly wrong, Here is the relevant info." + System.out.println("Something went horribly wrong, Here is the relevant info." +
"\nEvaluation: " + eval(expression.toString()) + "\nEvaluation: " + eval(expression.toString()) +
@@ -37,23 +38,25 @@ public class Obf {
} }
String comp = Complexers.complex(ri,Countroll.deep); String comp = Complexers.complex(ri,Countroll.deep);
String incr = Increasers.increase(current,target,ri,Countroll.deep); // Case for if its below
if (current < target) { if (current < target) {
Countroll.addCount++; Countroll.addCount++;
expression.append("<&b>+<&r><&e>").append(comp).append("<&r>"); expression.append("<&b>+<&r><&e>").append(comp).append("<&r>");
if (target - current > 128) { if (target - current > 128) {
expression.append("<&b>+<&r><&e>").append(incr).append("<&r>"); expression.append("<&b>*<&r><&e>").append(Increasers.increase(current,target,ri,Countroll.deep)).append("<&r>");
} }
} }
// Case for if its above
if (current > target) { if (current > target) {
Countroll.subCount++; Countroll.subCount++;
expression.append("<&b>-<&r><&e>").append(comp).append("<&r>"); expression.append("<&b>-<&r><&e>").append(comp).append("<&r>");
if (current - target > 128) { if (current - target > 128) {
expression.append("<&b>-<&r><&e>").append(incr).append("<&r>"); expression.append("<&b>-<&r><&e>").append(Increasers.increase(target,current,ri,Countroll.deep)).append("<&r>");
} }
} }
} }
Verbose.send("PROC", "Broke out of loop.");
return expression.toString(); return expression.toString();
} }
/** /**