Skip to content

Instantly share code, notes, and snippets.

@yKimisaki
Last active April 16, 2020 04:28
Show Gist options
  • Save yKimisaki/e9b8c643628e96c9d4629f832b9930ed to your computer and use it in GitHub Desktop.
Save yKimisaki/e9b8c643628e96c9d4629f832b9930ed to your computer and use it in GitHub Desktop.
using System;
namespace UhoProtocol
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Uho("Hello, World!"));
Console.WriteLine(Ohu(Uho("Hello, World!")));
}
static unsafe string Uho(string value)
{
var length = value.Length * 8;
var result = stackalloc char[length];
for (var i = 0; i < value.Length; ++i)
{
var x = (byte)value[i];
for (var j = 0; j < 8; ++j)
{
var isTrue = (x & (1 << j)) > 0;
result[i * 8 + j] = isTrue ? 'ウ' : 'ホ';
}
}
return "ウホ" + new string(result, 0, length);
}
static string Ohu(string value)
{
var valueSpan = value.AsSpan(2);
var result = new char[valueSpan.Length / 8];
for (var i = 0; i < result.Length; ++i)
{
var x = new byte();
for (var j = 0; j < 8; ++j)
{
if (valueSpan[i * 8 + j] == 'ウ')
{
x |= (byte)(1 << j);
}
}
result[i] = (char)x;
}
return new string(result);
}
}
}
@yKimisaki
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment