From a9ed131c8db7bcbf24f1764785aaea170c890ce9 Mon Sep 17 00:00:00 2001 From: kuyaya Date: Tue, 10 Nov 2020 13:26:45 +0100 Subject: [PATCH] Update Program.cs --- BadMorals/Program.cs | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/BadMorals/Program.cs b/BadMorals/Program.cs index d9e49c8..439cc47 100644 --- a/BadMorals/Program.cs +++ b/BadMorals/Program.cs @@ -6,21 +6,35 @@ public class Program { static string s1 = "2SXFnY5yWMMHytNyzMM3uYFzzcZnuMNzzXXzzNMunZczzFYu3MMzyNtyHMMWy5YnFXS2"; static string s2 = "fdmbxkHNsB3XGR1Q"; - static string s3 = "::PNDlGpXpoR:7"; static char[] a = s1.ToCharArray(); static char[] b = s2.ToCharArray(); - static char[] c = s3.ToCharArray(); + static char[] c; + + static string build; public static void Main(string[] args) { + + //section 0: Read user input and possibly return the flag. The user input is currently: ":" + if (args.Length == 1) + { + build = args[0] + ":PNDlGpXpoR:7"; + c = build.ToCharArray(); + } + else + { + Console.Write("Usage: HV20.exe ARG"); + Environment.Exit(1); + } + + // Section 1: Get every second char of s1 string firstresult = ""; for (int i = 0; i < a.Length; i++) { if (i % 2 == 0) { - a[i] = a[i + 1]; - firstresult += a[i]; + firstresult += a[i+1]; } } @@ -32,7 +46,7 @@ public static void Main(string[] args) secondresult += b[u]; } - // Section 3: XOR the string with a fixed byte + // Section 3: XOR the userinput + string with a fixed byte string thirdresult = ""; byte q = 10; for (int z = 0; z < c.Length; z++) @@ -43,13 +57,17 @@ public static void Main(string[] args) } // Final section: Convert the two strings from Base64 and print it out. - string final = firstresult + thirdresult; - - byte[] bit = Convert.FromBase64String(final); - - string flag = System.Text.Encoding.ASCII.GetString(bit); - - Console.Write(flag); + try + { + string final = firstresult + thirdresult; + byte[] bit = Convert.FromBase64String(final); + string flag = System.Text.Encoding.ASCII.GetString(bit); + Console.Write(flag); + } + catch + { + Console.Write("Your input does not result in a valid Base64 string."); + } } } }