字节码转字符串
需求:先将UTF-8字符串转为Byte[],例如“Game\CS1.6中文版”转换后变为:
{ 47 61 6D 65 5C 43 53 31 2E 36 E4 B8 AD E6 96 87 E7 89 88 };
(2)、将转换后的字节数组逐字节与0x81异或,上例将变为:
{ C6 E0 EC E4 DD C2 D2 B0 AF B7 65 39 2C 67 17 06 66 08 09 };
(3)、将异或后的数组转为字符串,得到结果:
“C6E0ECE4DDC2D2B0AFB765392C671706660809”
现根据字符串怎么将“C6E0ECE4DDC2D2B0AFB765392C671706660809“还原成”Game\CS1.6中文版“??
string test="C6E0ECE4DDC2D2B0AFB765392C671706660809"
string strDir = string.Empty;
byte[] bytes = new byte[dl.Length / 2];
int j = 0;
for (int i = 0; i < test.Length; i += 2)
{
bytes[j] = (byte)(Convert.ToInt32(test.Substring(i, 2), 16) ^ 0x81);
j++;
} strDir = Encoding.UTF8.GetString(bytes);
string strDir = string.Empty;
byte[] bytes = new byte[dl.Length / 2];
int j = 0;
for (int i = 0; i < test.Length; i += 2)
{
bytes[j] = (byte)(Convert.ToInt32(test.Substring(i, 2), 16) ^ 0x81);
j++;
} strDir = Encoding.UTF8.GetString(bytes);