/// <summary> /// 从本地读取密钥 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImportKeys_Click(object sender, EventArgs e) { var a = this.openFileDialog1.ShowDialog(); if (a != DialogResult.OK) { return; } try { this.myCipherKeys = JsonConvert.DeserializeObject <MyCipherKeys>( File.ReadAllText(this.openFileDialog1.FileName, Encoding.UTF8)); // 填充数据 this.tbVigenereKey.Text = ArrayToString(this.myCipherKeys.VigenereKey); if (this.myCipherKeys.AffineKeyA == MyCipherKeys.InvalidIntValue) { this.tbAffineKeyA.Text = String.Empty; } else { this.tbAffineKeyA.Text = this.myCipherKeys.AffineKeyA.ToString(); } if (this.myCipherKeys.AffineKeyB == MyCipherKeys.InvalidIntValue) { this.tbAffineKeyB.Text = String.Empty; } else { this.tbAffineKeyB.Text = this.myCipherKeys.AffineKeyB.ToString(); } this.tbHillKey.Text = MatrixToString(this.myCipherKeys.HillMatrix); } catch (Exception exc) { MessageBox.Show("读取文件出错,错误信息:" + exc.Message, "读取文件出错", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="keys"></param> public MyCipher(MyCipherKeys keys) : this(keys.VigenereKey, keys.AffineKeyA, keys.AffineKeyB, keys.HillMatrix) { }