Added modes DuckGroup and Numselli modulus is on both of them.

This commit is contained in:
obvWolf
2023-11-05 06:55:14 -06:00
parent 65eaa9a100
commit 7a4f318be6
6 changed files with 326 additions and 126 deletions

View File

@@ -3,7 +3,7 @@ plugins {
} }
group 'me.trouper' group 'me.trouper'
version '0.0.2' version '0.0.3'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -1,29 +1,119 @@
package me.trouper.Functions; package me.trouper.Functions;
import me.trouper.Main;
import me.trouper.Utils.Utils;
import java.util.Random; import java.util.Random;
import static me.trouper.Functions.Eval.eval; import static me.trouper.Functions.Eval.eval;
import static me.trouper.Functions.Eval.isPerfectSquare;
public class Complexers { public class Complexers {
public static String divide(int i) {
/**
* Safe to use with D mode
* @param i Integer to divide
* @return Colored String
*/
public static String divide(int i, boolean deep) {
Main.divideCount++;
Random random = new Random(); Random random = new Random();
int factor = random.nextInt(9)+1; int factor = random.nextInt(9)+1;
int doubled = i * factor; int doubled = i * factor;
boolean expFac = false;
boolean expDoub = false;
if (isPerfectSquare(factor)) expFac = true;
if (isPerfectSquare(doubled)) expDoub = true;
String result = "<&f>(<&r><&e>" + doubled + "<&b>/<&r><&e>" + factor + "<&f>)<&r>"; String result = "<&f>(<&r><&e>" + doubled + "<&b>/<&r><&e>" + factor + "<&f>)<&r>";
if (eval(result) == i) { if (deep) {
return result; result = "<&3>(<&r><&d>" + ((expDoub) ? power(doubled,false) : divide(doubled,false)) + "<&b>/<&r><&d>" + ((expFac) ? power(factor,false) : divide(factor,false)) + "<&3>)<&r>";
} }
return "(" + i + ")"; if (eval(result) != i) Utils.verbose("Failed to divide " + i + ", Attempted: " + result + "=" + eval(result));
return eval(result) == i ? result : "(" + i + ")";
} }
public static String root(int i) { /**
* Safe to use with D mode
* Only to be used with perfect squares
* @param i Integer to root+square
* @return Colored String
*/
public static String power(int i, boolean deep) {
Main.powerCount++;
if (!Eval.isPerfectSquare(i)) {
return "(" + i + ")";
}
int root = (int) Math.sqrt(i);
String result = "<&r><&f>(<&e>" + root + "<&b>^<&e>2<&f>)<&r>";
if (deep) {
result = "<&r><&3>(<&d>" + divide(root,false) + "<&b>^<&d>2<&3>)<&r>";
}
if (eval(result) != i) Utils.verbose("<&ch>Failed to power <&r>" + i + ", Attempted: " + result + "=" + eval(result));
return eval(result) == i ? result : "(" + i + ")";
}
/**
* Uses sqrt(), not safe with D mode
* @param i integer to square+root
* @return Colored String
*/
public static String root(int i, boolean deep) {
Main.rootCount++;
int squared = (int) Math.pow(i,2); int squared = (int) Math.pow(i,2);
String result = "<&9>sqrt<&r><&f>(<&r><&e>" + squared + "<&f>)<&r>"; String result = "<&9>sqrt<&r><&f>(<&r><&e>" + squared + "<&f>)<&r>";
if (eval(result) == i){ if (deep) {
return result; result = "<&1>sqrt<&r><&3>(<&r><&d>" + divide(squared,false) + "<&3>)<&r>";
} }
return "(" + i + ")"; if (eval(result) != i) Utils.verbose("<&ch>Failed to root <&r>" + i + ", Attempted: " + result + "=" + eval(result));
return (eval(result) == i) ? result : "(" + i + ")";
}
/**
* Uses modulus (ri%divisor)=i
* @param i Modulus to return
* @return Colored string
*/
public static String mRootDivisor(int i, boolean deep) {
Main.rDivisorCount++;
Random random = new Random();
int dividend = random.nextInt(9)+i+10;
int divisor = Utils.moduRootDivisor(dividend,i);
String result = "<&r><&f>(<&e>" + dividend + "<&b>%<&e>" + divisor + "<&f>)<&r>";
Utils.verbose("<&dh><&b>mRootDivisor has been ran!<&r>" +
"\nWanted: " + i +
"\nDivisor: " + divisor +
"\nDividend: " + dividend +
"\nCheck: " + dividend + "%" + divisor + "=" + i +
"\nResult: " + result);
if (eval(result) != i) Utils.verbose("<&ch>Failed to mRootDivisor<&r> " + i + ", Attempted: " + result + "=" + eval(result));
return (eval(result) == i) ? result : "(" + i + ")";
}
/**
* Uses modulus (dividend%ri)=i
* @param i Modulus to return
* @return Colored String
*/
public static String mRootDividend(int i, boolean deep) {
Main.rDividendCount++;
Random random = new Random();
int divisor = random.nextInt(9)+i+10;
int dividend = Utils.moduRootDividend(divisor,i);
String result = "<&r><&f>(<&e>" + dividend + "<&b>%<&e>" + divisor + "<&f>)<&r>";
Utils.verbose("<&dh><&b>mRootDividend has been ran!<&r>" +
"\nWanted:" + i +
"\nDivisor: " + divisor +
"\nDividend: " + dividend +
"\nCheck: " + dividend + "%" + divisor + "=" + i +
"\nResult: " + result);
if (eval(result) != i) Utils.verbose("<&ch>Failed to mRootDividend<&r> " + i + ", Attempted: " + result + "=" + eval(result));
return (eval(result) == i) ? result : "(" + i + ")";
} }
} }

View File

@@ -1,22 +1,29 @@
package me.trouper.Functions; package me.trouper.Functions;
import static me.trouper.Functions.Eval.eval; import static me.trouper.Functions.Eval.eval;
import static me.trouper.Functions.Eval.isPerfectSquare;
public class Increasers { public class Increasers {
public static String multiply(int i, int factor) { public static String multiply(int i, int factor, boolean deep) {
boolean useExp = isPerfectSquare(i);
String result = "<&7>(<&r><&2>" + i + "<&b>*<&r><&2>" + factor + "<&7>)<&r>"; String result = "<&7>(<&r><&2>" + i + "<&b>*<&r><&2>" + factor + "<&7>)<&r>";
if (eval(result) == i * factor) { if (deep) {
return result; result = "<&7>(<&r><&2>" + (useExp ? Complexers.power(i,true) : Complexers.divide(i,true)) + "<&b>*<&r><&2>" + factor + "<&7>)<&r>";
} }
return "(" + i + ")";
return eval(result) == i * factor ? result : "(" + i + ")";
} }
public static String power(int i, int exp) { public static String power(int i, int exp, boolean deep) {
boolean useExp = isPerfectSquare(i);
String result = "<&7>(<&r><&2>" + i + "<&b>^<&r><&2>" + exp + "<&7>)<&r>"; String result = "<&7>(<&r><&2>" + i + "<&b>^<&r><&2>" + exp + "<&7>)<&r>";
if (eval(result) == Math.pow(i,exp)) { if (deep) {
return result; result = "<&7>(<&r><&2>" + (useExp ? Complexers.power(i,true) : Complexers.divide(i,true)) + "<&b>^<&r><&2>" + exp + "<&7>)<&r>";
} }
return "(" + i + ")";
return eval(result) == Math.pow(i,exp) ? result : "(" + i + ")";
} }
} }

View File

@@ -1,5 +1,7 @@
package me.trouper.Functions; package me.trouper.Functions;
import me.trouper.Main;
import java.util.Random; import java.util.Random;
import static me.trouper.Functions.Eval.*; import static me.trouper.Functions.Eval.*;
@@ -8,7 +10,13 @@ import static me.trouper.Utils.Utils.removeColors;
import static me.trouper.Utils.Utils.verbose; import static me.trouper.Utils.Utils.verbose;
public class Obf { public class Obf {
public static String obfInt(int target, boolean deep) { /**
* ObfIntN will work for Numselli's counting bot
* @param target Integer to reach
* @param deep When True, doubles the use of Complexers and Increasers
* @return A colored string
*/
public static String obfIntN(int target, boolean deep) {
if (deep) System.out.println("Deep Obfuscation is coming soon!"); if (deep) System.out.println("Deep Obfuscation is coming soon!");
StringBuilder expression = new StringBuilder(); StringBuilder expression = new StringBuilder();
@@ -18,17 +26,9 @@ public class Obf {
verbose("Initializing Expression: " + initializer); verbose("Initializing Expression: " + initializer);
expression.append("<&dh><&f>").append(initializer).append("<&r>"); 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) { while (eval(expression.toString()) != target) {
total++; Main.total++;
int eval = (int) eval(expression.toString()); int eval = (int) eval(expression.toString());
int ri = random.nextInt(9)+1; int ri = random.nextInt(9)+1;
int op = random.nextInt(2); int op = random.nextInt(2);
@@ -47,77 +47,128 @@ public class Obf {
verbose("Current: " + eval(expression.toString())); verbose("Current: " + eval(expression.toString()));
if (isPerfectSquare(eval) && eval != 1) { if (isPerfectSquare(eval) && eval != 1) {
perfectCount++; Main.perfectCount++;
verbose("PERFECT SQUARE TIME! (" + perfectCount+ ")"); verbose("PERFECT SQUARE TIME! (" + Main.perfectCount+ ")");
expression.insert(0,"<&eh><&b>sqrt(<&r>").append("<&eh><&b>)<&r>"); expression.insert(0,"<&eh><&b>sqrt(<&r>").append("<&eh><&b>)<&r>");
eval = (int) eval(expression.toString()); eval = (int) eval(expression.toString());
} }
if (target - eval > 4069) {
mult = true; final String toAdd = complex(ri,deep,"n");
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) { if (eval < target) {
addCount++; if (target - eval > 4069) {
if (op == 0) { Main.expCount++;
divideCount++; verbose("Large than (" + Main.expCount + ")");
} else { expression.append("<&b>*<&r><&a>").append(Increasers.power(ri,3,deep)).append("<&r>");
rootCount++; } else if (target - eval > 1048) {
Main.expCount++;
verbose("Large than (" + Main.expCount + ")");
expression.append("<&b>*<&r><&a>").append(Increasers.power(ri,2,deep)).append("<&r>");
} else if (target - eval > 128) {
Main.factorCount++;
verbose("Big than (" + Main.factorCount + ")");
expression.append("<&b>*<&r><&a>").append(Increasers.multiply(ri,9,deep)).append("<&r>");
} }
Main.addCount++;
final String toAdd = (op == 0) ? Complexers.divide(ri) : Complexers.root(ri); expression.append("<&b>+<&r><&e>").append(toAdd).append("<&r>");
verbose("Less than (" + Main.addCount + ")");
expression.append((mult) ? "<&b>*<&r>" : "<&b>+<&r><&e>").append(toAdd).append("<&r>");
verbose("Less than (" + addCount + ")");
} }
if (eval > target) { if (eval > target) {
subCount++; Main.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.insert(0,"<&c>(<&r>").append("<&c>)<&r>");
expression.append("<&b>-<&r><&e>").append(toAdd).append("<&r>"); expression.append("<&b>-<&r><&e>").append(toAdd).append("<&r>");
verbose("Greater than (" + subCount + ")"); verbose("Greater than (" + Main.subCount + ")");
} }
} }
verbose("Broke out of loop. Value: " + eval(expression.toString())); verbose("Broke out of loop. Value: " + eval(expression.toString()));
verbose("Expression: " + expression); verbose("Expression: " + expression);
verbose("Expression (Cleaned): " + removeColors(expression.toString())); 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(); return expression.toString();
} }
/**
* ObfIntD will work with DuckGroups's Counting bot
* @param target Integer to reach
* @param deep When True, doubles the use of Complexers and Increasers
* @return A colored string
*/
public static String obfIntD(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>");
while (eval(expression.toString()) != target) {
Main.total++;
int eval = (int) eval(expression.toString());
int ri = random.nextInt(9)+1;
final String toAdd = complex(ri,deep,"d");
if (eval < target) {
if (target - eval > 4096) {
Main.expCount++;
expression.append("<&b>*<&r>").append(Increasers.power(ri,4,deep));
} else if (target - eval > 1048) {
Main.expCount++;
expression.append("<&b>*<&r>").append(Increasers.power(ri,2,deep));
} else if (target - eval > 128) {
Main.factorCount++;
expression.append("<&b>*<&r>").append(Increasers.multiply(ri,2,deep));
}
Main.addCount++;
expression.append("<&b>+<&r>").append(toAdd);
}
if (eval > target) {
if (eval - target > 4096) {
Main.expCount++;
expression.append("<&b>-<&r>").append(Increasers.power(ri,5,deep));
} else if (eval - target> 1048) {
Main.expCount++;
expression.append("<&b>-<&r>").append(Increasers.power(ri,3,deep));
} else if (eval - target > 128) {
Main.factorCount++;
expression.append("<&b>-<&r>").append(Increasers.multiply(ri,2,deep));
}
Main.subCount++;
expression.insert(0,"<&c>(<&r>").append("<&c>)<&r>");
expression.append("<&b>-<&r>").append(toAdd);
}
}
return expression.toString();
}
public static String increase(int target, int current, boolean deep, String mode) {
return target + "" + current;
}
public static String complex(int target, boolean deep, String mode) {
Random random = new Random();
String toAdd = "(" + target + ")";
int rComplexer;
switch (mode) {
case "n" -> rComplexer = random.nextInt(4)+1;
case "d" -> rComplexer = random.nextInt(3)+1;
default -> rComplexer = 1;
}
if (target == 1) {
toAdd = Complexers.power(target,deep);
} else if (isPerfectSquare(target)) {
toAdd = Complexers.power(target,deep);
} else {
switch (rComplexer) {
case 1 -> toAdd = Complexers.divide(target,deep);
case 2 -> toAdd = Complexers.mRootDivisor(target,deep);
case 3 -> toAdd = Complexers.mRootDividend(target,deep);
case 4 -> toAdd = Complexers.root(target,deep); // Won't reach this one, if its "d" due to it stopping at 3
}
}
return (eval(toAdd) == target) ? toAdd : "(" + target + ")";
}
} }

View File

@@ -14,9 +14,35 @@ public class Main {
public static boolean deep; public static boolean deep;
public static boolean color; public static boolean color;
public static boolean printHelp; public static boolean printHelp;
/* Statistics */
public static int expCount = 0;
public static int factorCount = 0;
public static int addCount = 0;
public static int subCount = 0;
public static int divideCount = 0;
public static int powerCount = 0;
public static int rDivisorCount = 0;
public static int rDividendCount = 0;
public static int rootCount = 0;
public static int perfectCount = 0;
public static int total = 0;
public static void clearStats() {
expCount = 0;
factorCount = 0;
addCount = 0;
subCount = 0;
divideCount = 0;
powerCount = 0;
rDivisorCount = 0;
rDividendCount = 0;
rootCount = 0;
perfectCount = 0;
total = 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);
boolean doCopy = false; boolean doCopy = false;
String mode = "N";
for (String arg : args) { for (String arg : args) {
@@ -26,6 +52,27 @@ public class Main {
case "--deep", "-d" -> deep = true; case "--deep", "-d" -> deep = true;
case "--color", "-rgb" -> color = true; case "--color", "-rgb" -> color = true;
case "--help", "--h", "-h" -> printHelp = true; case "--help", "--h", "-h" -> printHelp = true;
case "--mode=numselli", "-m=n" -> mode = "N";
case "--mode=duckgroup", "-m=d" -> mode = "D";
case "--mode=TEST" -> mode = "TEST";
}
}
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());
}
} }
} }
@@ -37,17 +84,33 @@ public class Main {
if (scanner.hasNextInt()) { if (scanner.hasNextInt()) {
int target = scanner.nextInt(); int target = scanner.nextInt();
Timer obfTimer = Timer.start(); Timer obfTimer = Timer.start();
String expression = Obf.obfInt(target, deep); String expression = null;
switch (mode) {
case "N" -> expression = Obf.obfIntN(target, deep);
case "D" -> expression = Obf.obfIntD(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("\nTarget Integer: " + target); System.out.println("\nStatistics" +
"\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("\nElapsed Time: " + obfTime + "ms");
System.out.println("\nTarget Integer: " + target);
if (output == target) { if (output == target) {
System.out.println(Utils.activateColors("<&2h><&f>Expression Correct<&r>\n\n" + ((color) ? expression : removeColors(expression)))); System.out.println(Utils.activateColors("<&2h><&f>Expression Correct<&r>\n\n" + ((color) ? expression : removeColors(expression))));
if (doCopy) Utils.copyToClip(removeColors(expression)); if (doCopy) Utils.copyToClip(removeColors(expression));
clearStats();
} else { } else {
System.out.println(Utils.activateColors("<&ch><&0>!!!! INCORRECT !!!!<&r>\n\n" + ((color) ? expression : removeColors(expression)))); System.out.println(Utils.activateColors("<&ch><&0>!!!! INCORRECT !!!!<&r>\n\n" + ((color) ? expression : removeColors(expression))));
} }
@@ -59,4 +122,5 @@ public class Main {
scanner.close(); scanner.close();
} }
} }

View File

@@ -15,7 +15,7 @@ public class Utils {
clipboard.setContents(parsed,null); clipboard.setContents(parsed,null);
} }
public static void verbose(String text) { public static void verbose(String text) {
if (Main.verbose) System.out.println(text); if (Main.verbose) System.out.println(activateColors(text));
} }
public static String removeColors(String input) { public static String removeColors(String input) {
return input.replaceAll("<&[0-9a-fr]>|<&[0-9a-frh]h>", ""); return input.replaceAll("<&[0-9a-fr]>|<&[0-9a-frh]h>", "");
@@ -58,49 +58,37 @@ public class Utils {
"\n<&e>Yellow:<&r> Complexer"; "\n<&e>Yellow:<&r> Complexer";
System.out.println(activateColors(colorKey)); System.out.println(activateColors(colorKey));
} }
/*
public static String highlightReg(String exp) { /**
final String result = exp * Returns the divisor of a mod equation given the modulus and dividend
.replaceAll("\\(", ANSI.WHITE + "(" + ANSI.RESET) * 5%x=2 -> x=3
.replaceAll("\\)", ANSI.WHITE + ")" + ANSI.RESET) * @param modulus Remainder
.replaceAll("\\*", ANSI.BLUE + "*" + ANSI.RESET) * @param dividend The number that is getting divided
.replaceAll("/", ANSI.BLUE + "/" + ANSI.RESET) * @return The divisor
.replaceAll("\\+", ANSI.BLUE + "+" + ANSI.RESET) */
.replaceAll("-", ANSI.BLUE + "-" + ANSI.RESET) public static int moduRootDivisor(int dividend, int modulus) {
.replaceAll("\\^", ANSI.BLUE + "^" + ANSI.RESET) int divisor = dividend - modulus;
.replaceAll("\\d+", ANSI.GREEN + "$0" + ANSI.RESET); verbose("<&1h><&e>Finding mrDivisor:<&r> " +
verbose("Attempting Ansi Highlight: " + result); "\nDividend (Given): " + dividend +
return result; "\nDivisor (Unknown): " + divisor +
"\nModulus (Given): " + modulus);
return divisor;
} }
public static String highlightDeep(String exp) { /**
final String result = exp * Returns the dividend of a mod equation given the modulus and divisor
.replaceAll("\\(", ANSI.CYAN + "*" + ANSI.RESET) * x%3=2 -> x=5
.replaceAll("\\)", ANSI.CYAN + "*" + ANSI.RESET) * @param modulus Remainder
.replaceAll("\\*", ANSI.BLUE + "*" + ANSI.RESET) * @param divisor The number that does the dividing
.replaceAll("/", ANSI.BLUE + "/" + ANSI.RESET) * @return The dividend
.replaceAll("\\+", ANSI.BLUE + "+" + ANSI.RESET) */
.replaceAll("-", ANSI.BLUE + "-" + ANSI.RESET) public static int moduRootDividend(int divisor, int modulus) {
.replaceAll("\\^", ANSI.BLUE + "^" + ANSI.RESET) int dividend = modulus + divisor;
.replaceAll("\\d+", ANSI.PURPLE + "$0" + ANSI.RESET); verbose("<&1h><&e>Finding mrDivisor:<&r> " +
verbose("Attempting Ansi Highlight (Deep): " + result); "\nDividend (Unknown): " + dividend +
return result; "\nDivisor (Given): " + divisor +
"\nModulus (Given): " + modulus);
return dividend;
} }
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();
}*/
} }