Skip to content

Instantly share code, notes, and snippets.

@key-moon
Last active October 6, 2018 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save key-moon/3d7cc6dc23203938fe87bd7e32e561d1 to your computer and use it in GitHub Desktop.
Save key-moon/3d7cc6dc23203938fe87bd7e32e561d1 to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
//自製TCP接続ライブラリの初期化(接続)
var stream = new TCPStream("2018shell2.picoctf.com", 14390, Encoding.UTF8);
while (true)
{
//問題文を表示
Console.WriteLine(stream.ReadToEnd());
//使うbaseを入力
int b = int.Parse(Console.ReadLine());
//結果を計算
string res = Console.ReadLine().Split().Select(x => GetChar(x, b)).Aggregate((x, y) => x + y);
//コンソールに出す
Console.WriteLine(res);
//TCPで送信
stream.WriteLine(res);
}
}
//bsaeを使ってbitsをデコード
static string GetChar(string bits,int b)
{
//Hex(b=16)の時だけ特殊処理
if (b == 16)
{
string res = "";
for (int i = 0; i < bits.Length; i += 2)
{
res += char.ConvertFromUtf32(Convert.ToInt32(bits.Substring(i, 2), b));
}
return res;
}
return char.ConvertFromUtf32(Convert.ToInt32(bits,b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment