通过使用以下代码,我设法解码了给定的十六进制字符串。在 C# 中,使用它的库函数,我可以将十六进制值解码为 ASCII、Unicode、Big-endian Unicode、UTF8、UTF7、UTF32。您能告诉我如何将十六进制字符串转换为其他解码样式,例如 ROT13、UTF16、西欧、HFS Plus 等。
{
string hexString = "68656c6c6f2c206d79206e616d6520697320796f752e";
byte[] dBytes = StringToByteArray(hexString);
//To get ASCII value of the hex string.
string ASCIIresult = System.Text.Encoding.ASCII.GetString(dBytes);
MessageBox.Show(ASCIIresult, "Showing value in ASCII");
//To get the Unicode value of the hex string
string Unicoderesult = System.Text.Encoding.Unicode.GetString(dBytes);
MessageBox.Show(Unicoderesult, "Showing value in Unicode");
}
public static byte[] StringToByteArray(String hex)
{
int NumberChars = hex.Length / 2;
byte[] bytes = new byte[NumberChars];
using (var sr = new StringReader(hex))
{
for (int i = 0; i < NumberChars; i++)
bytes[i] =
Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16);
}
return bytes;
}