Cleaned up the main class and finished the config manager
This commit is contained in:
28
README.md
28
README.md
@@ -53,6 +53,34 @@ Make sure you have Java 17 or higher installed on your system!
|
||||
3. Build with gradle `$ ./gradlew build`
|
||||
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
|
||||
Development will continue with the addition of bitwise operations AND (&) and OR (|)
|
||||
- Both bots support these operators, and it will be in both modes
|
||||
|
||||
@@ -10,9 +10,11 @@ import me.trouper.Utils.Verbose;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static me.trouper.Functions.Eval.eval;
|
||||
import static me.trouper.Utils.Utils.copyToClip;
|
||||
import static me.trouper.Utils.Utils.removeColors;
|
||||
|
||||
public class Countroll {
|
||||
public static boolean showProgress;
|
||||
public static boolean doCopy;
|
||||
public static boolean deep;
|
||||
public static boolean color;
|
||||
@@ -47,10 +49,35 @@ public class Countroll {
|
||||
errorCount = 0;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
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) {
|
||||
switch (arg) {
|
||||
case "--copy", "-c" -> doCopy = true;
|
||||
@@ -64,80 +91,92 @@ public class Countroll {
|
||||
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);
|
||||
Complexers.useRoot = true;
|
||||
Complexers.usePower = true;
|
||||
Complexers.useDivide = true;
|
||||
Complexers.useRDivisor = true;
|
||||
Complexers.useRDividend = true;
|
||||
if (mode.equals("D")) Complexers.useRoot = false;
|
||||
if (userInput.equals("exit")) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (mode.equals("TEST")) {
|
||||
while (true) {
|
||||
System.out.print("Enter an expression (or 'exit' to exit): ");
|
||||
String userInput = scanner.next();
|
||||
|
||||
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());
|
||||
}
|
||||
try {
|
||||
double result = eval(userInput);
|
||||
System.out.println("Result: " + result);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (printHelp) Utils.printHelp();
|
||||
if (color) Utils.printColorKey();
|
||||
|
||||
private static void handleTargetIntegers(Scanner scanner) {
|
||||
while (true) {
|
||||
System.out.print("Enter Target Integer: ");
|
||||
if (scanner.hasNextInt()) {
|
||||
int target = scanner.nextInt();
|
||||
|
||||
Timer obfTimer = Timer.start();
|
||||
String expression = null;
|
||||
|
||||
expression = Obf.obfIntN(target,deep);
|
||||
|
||||
String expression = Obf.obfInt(target);
|
||||
long obfTime = obfTimer.end().timePassed();
|
||||
|
||||
double output = eval(removeColors(expression));
|
||||
|
||||
System.out.println("\nStatistics" +
|
||||
"\nErrors: " + errorCount +
|
||||
"\nExponents: " + expCount +
|
||||
"\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))));
|
||||
}
|
||||
printStatistics(obfTime);
|
||||
printReport(target,expression,output);
|
||||
if (doCopy) copyToClip(removeColors(expression));
|
||||
} else {
|
||||
System.out.println("Exiting the program.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
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
|
||||
╚══════════════════════════
|
||||
|
||||
>> %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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import me.trouper.Countroll;
|
||||
import me.trouper.Functions.Complexers;
|
||||
import me.trouper.Utils.Verbose;
|
||||
|
||||
import java.io.*;
|
||||
@@ -23,7 +24,7 @@ public class ConfigManager {
|
||||
try (Reader reader = new FileReader(configFile)) {
|
||||
Gson gson = new Gson();
|
||||
Map<String, Object> config = gson.fromJson(reader, HashMap.class);
|
||||
setMainClassVariables(config);
|
||||
getConfig(config);
|
||||
} catch (JsonSyntaxException | JsonIOException | IOException e) {
|
||||
e.printStackTrace();
|
||||
generateDefaultConfig();
|
||||
@@ -33,11 +34,16 @@ public class ConfigManager {
|
||||
|
||||
private static void generateDefaultConfig() {
|
||||
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("deep", false);
|
||||
defaultConfig.put("color", false);
|
||||
defaultConfig.put("color", true);
|
||||
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.processes",true);
|
||||
defaultConfig.put("verbose.loops",false);
|
||||
@@ -53,11 +59,16 @@ public class ConfigManager {
|
||||
} catch (IOException e) {
|
||||
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");
|
||||
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.deep = (boolean) config.get("deep");
|
||||
Countroll.color = (boolean) config.get("color");
|
||||
|
||||
@@ -15,7 +15,6 @@ public class Complexers {
|
||||
public static boolean usePower;
|
||||
public static boolean useRoot;
|
||||
public static boolean useRDividend;
|
||||
public static boolean useRDivisor;
|
||||
|
||||
public static String pickComplexer() {
|
||||
List<String> enabledComplexers = new ArrayList<>();
|
||||
@@ -24,7 +23,6 @@ public class Complexers {
|
||||
if (usePower) enabledComplexers.add("power");
|
||||
if (useRoot) enabledComplexers.add("root");
|
||||
if (useRDividend) enabledComplexers.add("mrDividend");
|
||||
if (useRDivisor) enabledComplexers.add("mrDivisor");
|
||||
|
||||
Collections.shuffle(enabledComplexers);
|
||||
if (!enabledComplexers.isEmpty()) {
|
||||
@@ -41,7 +39,9 @@ public class Complexers {
|
||||
return divide(i,deep);
|
||||
}
|
||||
case "power" -> {
|
||||
if (!isPerfectSquare(i)) return complex(i,deep);
|
||||
if (!isPerfectSquare(i)) {
|
||||
return divide(i,deep);
|
||||
}
|
||||
return power(i,deep);
|
||||
}
|
||||
case "root" -> {
|
||||
@@ -50,9 +50,6 @@ public class Complexers {
|
||||
case "mrDividend" -> {
|
||||
return mRootDividend(i,deep);
|
||||
}
|
||||
case "mrDivisor" -> {
|
||||
return mRootDivisor(i,false);
|
||||
}
|
||||
default -> {
|
||||
return divide(i,false);
|
||||
}
|
||||
@@ -118,32 +115,6 @@ public class Complexers {
|
||||
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
|
||||
* @param i Modulus to return
|
||||
|
||||
@@ -14,43 +14,56 @@ import static me.trouper.Functions.Eval.isPerfectSquare;
|
||||
public class Increasers {
|
||||
|
||||
public static String increase(int current, int target, int i, boolean deep) {
|
||||
|
||||
if (target - current > 4069) {
|
||||
return power(i,10,deep);
|
||||
} else if (target - current > 10000000) {
|
||||
return power(i,8,deep);
|
||||
} else if (target - current > 1000000) {
|
||||
return power(i,6,deep);
|
||||
} else if (target - current > 100000) {
|
||||
return power(i,4,deep);
|
||||
} else if (target - current > 10000) {
|
||||
return power(i,3,deep);
|
||||
} else if (target - current > 1000) {
|
||||
return power(i,2,deep);
|
||||
} else if (target - current > 100) {
|
||||
return multiply(i,9,deep);
|
||||
if (target - current > 64000) {
|
||||
Countroll.expCount++;
|
||||
return Increasers.power(i,4,deep);
|
||||
} else if (target - current > 4069) {
|
||||
Countroll.expCount++;
|
||||
return Increasers.power(i,3,deep);
|
||||
} else if (target - current > 1048) {
|
||||
Countroll.expCount++;
|
||||
return Increasers.power(i,2,deep);
|
||||
} else if (target - current > 128) {
|
||||
Countroll.factorCount++;
|
||||
return Increasers.multiply(i,9,deep);
|
||||
} else {
|
||||
return multiply(i,2,deep);
|
||||
}
|
||||
}
|
||||
public static String multiply(int i, int factor, boolean deep) {
|
||||
Countroll.factorCount++;
|
||||
String result = "<&7>(<&r><&2>" + i + "<&b>*<&r><&2>" + factor + "<&7>)<&r>";
|
||||
String result;
|
||||
|
||||
if (deep) {
|
||||
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) {
|
||||
Countroll.powerCount++;
|
||||
String result = "<&7>(<&r><&2>" + i + "<&b>^<&r><&2>" + exp + "<&7>)<&r>";
|
||||
String result;
|
||||
|
||||
if (deep) {
|
||||
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 + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,12 @@ public class Obf {
|
||||
// MAIN LOOP
|
||||
Verbose.send("PROC", "Beginning Main Loop: ");
|
||||
while (eval(expression.toString()) != target) {
|
||||
|
||||
Countroll.total++;
|
||||
int current = (int) eval(expression.toString());
|
||||
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()))) {
|
||||
System.out.println("Something went horribly wrong, Here is the relevant info." +
|
||||
"\nEvaluation: " + eval(expression.toString()) +
|
||||
@@ -37,23 +38,25 @@ public class Obf {
|
||||
}
|
||||
|
||||
String comp = Complexers.complex(ri,Countroll.deep);
|
||||
String incr = Increasers.increase(current,target,ri,Countroll.deep);
|
||||
|
||||
// Case for if its below
|
||||
if (current < target) {
|
||||
Countroll.addCount++;
|
||||
expression.append("<&b>+<&r><&e>").append(comp).append("<&r>");
|
||||
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) {
|
||||
Countroll.subCount++;
|
||||
expression.append("<&b>-<&r><&e>").append(comp).append("<&r>");
|
||||
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();
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user