Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
githubkuyaya authored Nov 10, 2020
1 parent ca4448d commit a9ed131
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions BadMorals/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand All @@ -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++)
Expand All @@ -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.");
}
}
}
}

0 comments on commit a9ed131

Please sign in to comment.