private String Decrypt(BlockInfo bi, String value) { //algo = new String[] { "RailFence", "MacierzoweA", "MacierzoweB", "MacierzoweC", "CezaraA", "CezaraB", "Vigenere" }; if (bi == null) return ""; if (bi.EncryptMethod.Equals(algo[0])) { return RailFence.Decrypt(Convert.ToInt32(bi.keyOne), value); } else if (bi.EncryptMethod.Equals(algo[1])) { return MacierzoweA.Decrypt(bi.keyOne, value); } else if (bi.EncryptMethod.Equals(algo[2])) { return MacierzoweB.Decrypt(bi.keyOne, value); } else if (bi.EncryptMethod.Equals(algo[3])) { return MacierzoweC.Decrypt(bi.keyOne, value); } else if (bi.EncryptMethod.Equals(algo[4])) { return CezaraA.Decrypt(Convert.ToInt32(bi.keyOne), value); } else if (bi.EncryptMethod.Equals(algo[5])) { return CezaraB.Decrypt(Convert.ToInt32(bi.keyOne), Convert.ToInt32(bi.keyTwo), value); } else if (bi.EncryptMethod.Equals(algo[6])) { Vigenere v = new Vigenere(bi.keyOne); return v.Encrypt(value); } return ""; }
private void setKeys(BlockInfo bi) { if (cbAlgorithms.SelectedItem.Equals(algo[5])) // CezaraB { bi.keyOne = Convert.ToString(numericUpDown1.Value); bi.keyTwo = Convert.ToString(numericUpDown2.Value); } else if (cbAlgorithms.SelectedItem.Equals(algo[4]) || cbAlgorithms.SelectedItem.Equals(algo[0])) { bi.keyOne = Convert.ToString(numericUpDown3.Value); } else { bi.keyOne = textKey.Text; } //Console.WriteLine("Dodaje klucze dla: " + bi.ToString()); }
private void button2_Click(object sender, EventArgs e) { try { int rot = Convert.ToInt32(numericUpDown4.Value); int bSize = Convert.ToInt32(numBlock.Value); String txt = text.Text.Substring(startIndex, bSize); for (int i = 0; i < rot; i++) { txt = Encrypt(txt); } BlockInfo bi = new BlockInfo(bSize, cbAlgorithms.SelectedItem.ToString(), rot); setKeys(bi); operations.Add(bi); //textResult.Text += Encrypt(text.Text.Substring(startIndex, Convert.ToInt32(numBlock.Value))); textResult.Text += txt; startIndex += Convert.ToInt32(numBlock.Value); } catch (ArgumentOutOfRangeException) { if (startIndex < text.Text.Length) { int size = text.Text.Length; int endIndex = size - startIndex; int rot = Convert.ToInt32(numericUpDown4.Value); String txt = text.Text.Substring(startIndex); for (int i = 0; i < rot; i++) { txt = Encrypt(txt); } BlockInfo bi = new BlockInfo(endIndex, cbAlgorithms.SelectedItem.ToString(), rot); setKeys(bi); operations.Add(bi); textResult.Text += txt; //textResult.Text += Encrypt(text.Text.Substring(startIndex, endIndex - 1)); startIndex += endIndex; } } labCount.Text = Convert.ToString(startIndex); }