0
我正在學習如何對字符串進行編碼和解碼。這是一種將我在網上找到的純文本解碼爲chob文本的方法。使用Base64String對已解碼的字符串進行編碼
public static string Decode(string chiperText)
{
byte[] numArray = Convert.FromBase64String(chiperText);
byte[] numArray1 = new byte[(int)numArray.Length - 1];
byte num = (byte)(numArray[0]^188);
for (int i = 1; i < (int)numArray.Length; i++)
{
numArray1[i - 1] = (byte)(numArray[i]^188^num);
}
return Encoding.ASCII.GetString(numArray1);
}
我的問題是我不知道如何編碼到原始狀態。我嘗試這種方法,它不起作用。
public static string Encode(string plainText)
{
byte[] bytes = Encoding.ASCII.GetBytes(plainText);
byte[] results = new byte[(int)bytes.Length - 1];
byte num = (byte)(bytes[0]^188);
for (int i = 1; i < bytes.Length; i++)
{
results[i - 1] = (byte)(bytes[i]^188^num);
}
return Convert.ToBase64String(results);
}
**不要發明自己的密碼**,也不要使用隨機在線發明的密碼。這是相當不安全的。 – SLaks
@SLaks不,它不是我的。我發現它幾乎沒有什麼變化。我只是學習不了多少。 – user3334858
不要使用其他隨機人發明的加密。這個密碼是無用的。 – SLaks