private void radioButton_CheckedChanged(object sender, EventArgs e) { if ((sender as RadioButton).Checked) { algo = (sender as RadioButton).Tag as algo; } }
/// <summary> /// 要加密 /// </summary> /// <param name="Data">要加密的字符串</param> /// <param name="key">密钥</param> /// <returns></returns> public string encrypt(string Data, string key) { try { if (Data.Length == 0) { throw new ArgumentException("Data must be at least 1 characater in length."); } uint[] k = FormatKey(key); if ((Data.Length % 8) != 0) { int num6 = (8 - (Data.Length % 8)) - 1; for (int j = 0; j <= num6; j++) { Data = Data + "\0"; } } //增加的 else { for (int j = 0; j <= 7; j++) { Data = Data + "\0"; } } ArrayList list = new ArrayList(Data.Length); list.AddRange(Encoding.Unicode.GetBytes(Data)); string str = ""; uint[] v = new uint[3]; byte[] buffer = new byte[5]; int num5 = list.Count - 1; for (int i = 0; i <= num5; i += 8) { int index = 0; do { buffer[index] = ByteType.FromObject(list[i + index]); index++; }while (index <= 3); v[0] = BitConverter.ToUInt32(buffer, 0); int num4 = 0; do { buffer[num4] = ByteType.FromObject(list[(i + 4) + num4]); num4++; }while (num4 <= 3); v[1] = BitConverter.ToUInt32(buffer, 0); algo algo = new algo(); algo.code(v, k); str = str + Util.ConvertUintToHexString(v[0]) + Util.ConvertUintToHexString(v[1]); } return(str.ToString()); } catch (Exception ex) { return("加密失败:" + ex.Message); } }
public void Init(algo[] algos) { // doit être défini avant this.algos = algos; if (algos.Length > 1) { radioButtons = new RadioButton[algos.Length]; for (int i = 0; i < algos.Length; ++i) { RadioButton rb = new RadioButton(); rb.AutoSize = true; rb.Location = new System.Drawing.Point(3, 23 * (i) + 3); rb.Size = new System.Drawing.Size(85, 17); rb.TabStop = true; rb.Text = algos[i].nom; rb.UseVisualStyleBackColor = true; rb.Tag = algos[i]; rb.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged); radioButtons[i] = rb; } panel1.Controls.AddRange(this.radioButtons); this.radioButtons[0].Checked = true; } else { // forcément algos.Length == 1 algo = algos[0]; comboBoxNiveaux.Location = new Point(0, 0); } //this.Text = algos.Aggregate("Les ", (s, x) => s += x.nom + ", "); string s = "Les "; for (int i = 0; i < algos.Length - 2; ++i) { s += algos[i].nom + ", "; } if (algos.Length >= 2) { s += algos[algos.Length - 2].nom + " et les "; } s += algos[algos.Length - 1].nom; this.Text = s; }
/// <summary> ///解密 /// </summary> /// <param name="Data">要解密的字符串</param> /// <param name="key">Key密钥</param> /// <returns></returns> public string decrypt(string Data, string key) { try { uint[] k = FormatKey(key); int index = 0; uint[] v = new uint[3]; byte[] bytes = new byte[(Data.Length / 2) + 1]; algo algo = new algo(); int num6 = Data.Length - 1; for (int i = 0; i <= num6; i += 0x10) { v[0] = Util.ConvertHexStringToUint(Data.Substring(i, 8)); v[1] = Util.ConvertHexStringToUint(Data.Substring(i + 8, 8)); algo.decode(v, k); int num4 = 0; do { bytes[index] = BitConverter.GetBytes(v[0])[num4]; index++; num4++; }while (num4 <= 3); int num5 = 0; do { bytes[index] = BitConverter.GetBytes(v[1])[num5]; index++; num5++; }while (num5 <= 3); } string str = Encoding.Unicode.GetString(bytes, 0, bytes.Length); int num = str.Length - 1; char[] chArray = str.ToCharArray(); while (chArray[num] == '\0') { num--; } return(str.Substring(0, num + 1)); } catch (Exception ex) { return("解密失败:" + ex.Message); } }
AssertAlgorithmProperties(algo, g, pos, expectedReportIterationEnd, expectedReportProgress, p);
public Checksum(algo algo, string hash) { _algo = algo; _hash = hash; }