HSCTF 2021 - Warmup | Rev
Warmup
Time to get warmed up!
Downloadable file: WarmupRev.java
import java.util.Scanner;
public class WarmupRev {
public static String cold(String t) {
return t.substring(17) + t.substring(0, 17);
}
public static String cool(String t) {
String s = "";
for (int i = 0; i < t.length(); i++)
if (i % 2 == 0)
s += (char) (t.charAt(i) + 3 * (i / 2));
else
s += t.charAt(i);
return s;
}
public static String warm(String t) {
String a = t.substring(0, t.indexOf("l") + 1);
String t1 = t.substring(t.indexOf("l") + 1);
String b = t1.substring(0, t1.indexOf("l") + 1);
String c = t1.substring(t1.indexOf("l") + 1);
return c + b + a;
}
public static String hot(String t) {
int[] adj = {-72, 7, -58, 2, -33, 1, -102, 65, 13, -64,
21, 14, -45, -11, -48, -7, -1, 3, 47, -65, 3, -18,
-73, 40, -27, -73, -13, 0, 0, -68, 10, 45, 13};
String s = "";
for (int i = 0; i < t.length(); i++)
s += (char) (t.charAt(i) + adj[i]);
return s;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Let's get warmed up! Please enter the flag: ");
String flag = in.nextLine();
String match = "4n_3nd0th3rm1c_rxn_4b50rb5_3n3rgy";
if (flag.length() == 33 && hot(warm(cool(cold(flag)))).equals(match))
System.out.println("You got it!");
else
System.out.println("That's not correct, please try again!");
in.close();
}
}
Solution
There are four functions in play.
Cold() will take the string starting from the 17th index and put it in front.
Cool() will take every character in even index and shift (3+i/2) to the right.
Warm() will split the string into four variables: a, t1, b, c
- a splits the string up to the first “l”
- t1 is the rest of the string after splitting a
- b splits the t1 string up to “l’ again
- c is the rest of the string after splitting b
Hot() will add shift each character of the string by the corresponding integer in the list “adj”.
Here is my rev. script. Please note that my script is not a general solution. I have assumed that the given string will always be flag{…l…} and there is only one extra “l” after the “l” in “flag”.
import java.util.Scanner;
public class WarmupRev {
public static String uncold(String t) {
return t.substring(16) + t.substring(0, 16);
}
public static String uncool(String t) {
String s = "";
for (int i = 0; i < t.length(); i++)
if (i % 2 == 0)
s += (char) (t.charAt(i) - 3 * (i / 2));
else
s += t.charAt(i);
return s;
}
public static String unwarm(String t) {
return t.substring(27) + t.substring(15, 27) + t.substring(0, 15);
}
public static String unhot(String t) {
int[] adj = { -72, 7, -58, 2, -33, 1, -102, 65, 13, -64, 21, 14, -45, -11, -48, -7, -1, 3, 47, -65, 3, -18, -73, 40,
-27, -73, -13, 0, 0, -68, 10, 45, 13 };
String s = "";
for (int i = 0; i < t.length(); i++)
s += (char) (t.charAt(i) - adj[i]);
return s;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Let's get warmed up! Please enter the flag: ");
String flag = in.nextLine(); // 4n_3nd0th3rm1c_rxn_4b50rb5_3n3rgy
System.out.println(uncold(uncool(unwarm(unhot(flag)))));
in.close();
}
}
Flag = flag{1ncr34s3_1n_3nth4lpy_0f_5y5}