Last active
April 16, 2020 04:28
-
-
Save yKimisaki/e9b8c643628e96c9d4629f832b9930ed 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; | |
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); | |
} | |
} | |
} |
Author
yKimisaki
commented
Jul 3, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment