|
/// <summary>
/// 自定义Base16解码
/// </summary>
/// <param name="str">需要解码的字符串</param>
/// <param name="autoCode">自定义Base16编码数组,16个元素,可以为数字、字符、特殊符号,若不填,使用默认的Base16编码数组,解码与编码的Base16编码数组一样</param>
/// <returns></returns>
public static string AutoBase16Decrypt(string str, string[] autoCode)
{
int k = 0;
string dnStr = string.Empty;
int strLength = str.Length;
if (autoCode == null || autoCode.Length < 16)
autoCode = new string[] { "a", "2", "B", "g", "E", "5", "f", "6", "C", "8", "o", "9", "Z", "p", "k", "M" };
byte[] data = new byte[strLength / 2];
for (int i = 0, j = 0; i < data.Length; i++, j++)
{
byte s = 0;
int index1 = autoCode.ToList().IndexOf(str[j].ToString());
j += 1;
int index2 = autoCode.ToList().IndexOf(str[j].ToString());
s = (byte)(s ^ index1);
s = (byte)(s << 4);
s = (byte)(s ^ index2);
data[k] = s;
k++;
}
dnStr = Encoding.Default.GetString(data);
return dnStr;
}
|
|