## HACKvent 2020 - Day 2

01-01-2021 - 1 minute, 16 seconds -

Challenge - Chinese Animals

The challenge description of day 2 read:

I've received this note from a friend, who is a Chinese CTF player:

Unfortunately, Google Translate wasn’t of much help. I suspect the data has somehow been messed up while transmitting it. Sadly, I can’t ask my friend about more details. The Great Chinese Firewall is thwarting our attempts to reach each other, and there’s no way I’m going to install WeChat on my phone.

"I suspect the data has somehow been messed up while transmitting it." sounded like an encoding issues to us. So we tried try a bunch, because who knows what encoding was used.

Well, actually we could have guessed the encoding. Obviously the destination encoding was to be something ASCII compatible, typically for the western hemisphere. The source encoding must have been some wide character encoding then, otherwise there wouldn't be many issues.

But we didn't, so we wrote more code than necessary:

static void Main()
{
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;

Console.WriteLine("Input string:");

PrintStringFromEncodingInAllEncodings(origString, Encoding.UTF8);
PrintStringFromEncodingInAllEncodings(origString, Encoding.ASCII);
PrintStringFromEncodingInAllEncodings(origString, Encoding.BigEndianUnicode);
PrintStringFromEncodingInAllEncodings(origString, Encoding.Default);
PrintStringFromEncodingInAllEncodings(origString, Encoding.Latin1);
PrintStringFromEncodingInAllEncodings(origString, Encoding.UTF32);
PrintStringFromEncodingInAllEncodings(origString, Encoding.UTF7);
PrintStringFromEncodingInAllEncodings(origString, Encoding.Unicode);

Console.WriteLine($"From {encoding.EncodingName}"); PrintBytesInAllEncodings(bytes); Console.WriteLine("------------------------"); } static void PrintBytesInAllEncodings(Span<byte> bytes) { PrintBytesInGivenEncoding(bytes, Encoding.ASCII); PrintBytesInGivenEncoding(bytes, Encoding.UTF8); PrintBytesInGivenEncoding(bytes, Encoding.BigEndianUnicode); PrintBytesInGivenEncoding(bytes, Encoding.Default); PrintBytesInGivenEncoding(bytes, Encoding.Latin1); PrintBytesInGivenEncoding(bytes, Encoding.UTF32); PrintBytesInGivenEncoding(bytes, Encoding.UTF7); PrintBytesInGivenEncoding(bytes, Encoding.Unicode); } static void PrintBytesInGivenEncoding(Span<byte> bytes, Encoding encoding) { Console.WriteLine($"{encoding.EncodingName}\t{encoding.GetString(bytes)}");
}
In hindsight, no surprise, the source encoding was UTF-16 BE. Converting correctly yielded HV20{small-elegant-butterfly-loves-grass-mud-horse}.