Last active
October 22, 2016 09:07
-
-
Save own2pwn/e0cff8c9cf9a18931f8d99b6662a5dd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
namespace CTFSleepingGuard | |
{ | |
internal static class Program | |
{ | |
private static void Test() | |
{ | |
var plain = Encoding.UTF8.GetBytes("PlainText"); | |
var encKey = Encoding.UTF8.GetBytes("S0m3Text"); | |
var encrypted = new byte[plain.Length]; | |
var obtainedKey = new byte[encKey.Length]; | |
for (var i = 0; i < plain.Length; i++) | |
encrypted[i] = (byte) (plain[i] ^ encKey[i%encKey.Length]); | |
for (var i = 0; i < encKey.Length; i++) | |
obtainedKey[i] = (byte) (encrypted[i] ^ plain[i]); | |
if (Encoding.UTF8.GetString(obtainedKey) == Encoding.UTF8.GetString(encKey)) | |
Console.WriteLine("y"); | |
} | |
private static void Main(string[] args) | |
{ | |
var b64Decoded = Convert.FromBase64String(File.ReadAllText("F:\\Progs\\NetCat\\b64")); | |
var normalPng = File.ReadAllBytes("F:\\Progs\\NetCat\\g.png"); | |
var key = new byte[12]; | |
Test(); | |
var decoded = new byte[b64Decoded.Length]; | |
for (var i = 0; i < 12; i++) | |
key[i] = (byte) (b64Decoded[i] ^ normalPng[i]); | |
for (var i = 0; i < b64Decoded.Length; i++) | |
decoded[i] = (byte) (b64Decoded[i] ^ key[i%key.Length]); | |
File.WriteAllBytes("F:\\Progs\\NetCat\\d.png", decoded); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment