Just a disclaimer up front, I don’t have a ton of coding experience – just enough to let me partially understand what’s happening in this code, but I’m struggling with how to arrive at the answer.
This block of code (I think is C#, could be JS) was given as part of a CTF challenge game that I’m playing, and I’m trying to get some advise or opinions on how to get this working correctly. It looks to be at least partially (maybe more) incomplete:
string input = "***********";
static void Challenge25_Starter(string input, BigInteger mul, BigInteger bigMul)
{
int len = str.Length;
BigInteger result = 0;
for (int i = 0; i < len; i++)
result += (int)str[i] * BigInteger.Pow(mul, len - i - 1) % bigMul; }
Challenge25_Starter(input, 256, Math.Pow(10,30));
//result = 63110558060474351068526900 What is the input?
Can anyone offer any insight as to how to get this working correctly? Again, I don’t have a lot of coding experience, so I’m just trying to figure out how to get this working so I can at least execute the code and then figure out what "input" is needed from there.
NOTE: The creator did say that "str" is not defined, and should be "input".
I’ve been trying to add the missing pieces to what looks to be like an incomplete block of code. Unfortunately, there’s no other instructions, guidance, or means to acquire hints given.
>Solution :
This is C# by the way, you have your specified known target value of 63110558060474351068526900 with the known mul and bigMul values. Iterating from 00000000000 -> 99999999999 till target value is found. The input would be 057921102001 in this case running the code. Example below.
using System;
using System.Numerics;
public class Program {
public static BigInteger CalculateResult(string input, BigInteger mul, BigInteger bigMul) {
int len = input.Length;
BigInteger result = 0;
for (int i = 0; i < len; i++) {
result += (int)input[i] * BigInteger.Pow(mul, len - i - 1) % bigMul;
}
return result;
}
public static void Main() {
BigInteger targetResult = 63110558060474351068526900;
BigInteger mul = 256;
BigInteger bigMul = BigInteger.Pow(10, 30);
string input = "00000000000"; // Start with a known input value
BigInteger result = CalculateResult(input, mul, bigMul);
while (result != targetResult && input.Length < 100) {
input = "0" + input; // Add one more leading zero to the input string
result = CalculateResult(input, mul, bigMul);
}
if (result == targetResult) {
Console.WriteLine("Input: " + input);
} else {
Console.WriteLine("No valid input found within the character limit.");
}
}
}