public void EncryptTest() { string key = "CONVENIENCE"; string input = "HERE IS A SECRET MESSAGE ENCIPHERED BY TRANSPOSITION"; string expected = "HEESPNI RR SSEES EIY A SCBT EMGEPN ANDI CT RTAHSO IEERO"; ColumnarTranspositionC ct = new ColumnarTranspositionC(key); string output = ct.Encrypt(input); Assert.AreEqual(output, expected); }
private void encryptDecryptPressed(object sender, RoutedEventArgs e) { string buttonName = ((Button)sender).Name; string userInput = mTextBox.Text.ToString(); string userKey = keyTextBox.Text.ToString(); string encrypted = ""; string decrypted = ""; bool normalDialog = true; switch (currentAlgorithm) { case "RAIL_FENCE": if (mTextBox.Text == "") { MessageBox.Show("Rail fence text input is empty. Please type in something."); return; } if (validateRailfenceFields(keyTextBox.Text.ToString())) { int i = int.Parse(userKey); rf = new RailFence(i); encrypted = rf.Encrypt(userInput); decrypted = rf.Decrypt(userInput); } break; case "COLUMNAR_TRANSP": if (mTextBox.Text == "") { MessageBox.Show("Columanr transp text input is empty. Please type in something."); return; } int[] inputTab = parseColumnarTranspKey(userKey); if (validateColumnarTranspkey(inputTab)) { ct = new ColumnarTransposition(parseColumnarTranspKey(userKey)); encrypted = ct.Encrypt(userInput); decrypted = ct.Decrypt(userInput); } else { return; } break; case "MATRIX_TRANSP": if (mTextBox.Text == "") { MessageBox.Show("Matrix transp text input is empty. Please type in something."); return; } if (validateMatrixTransp(userKey)) { mt = new MatrixTransp(parseMatrixTranspKey(userKey)); encrypted = mt.Encrypt(userInput); decrypted = mt.Decrypt(userInput); } else { return; } break; case "COLUMNAR_C": if (mTextBox.Text == "") { MessageBox.Show("Matrix transp version C text input is empty. Please type in something."); return; } if (validateMatrixTranspVerCKey(userKey) && validateMatrixTranspVerCWord(userInput)) { ctc = new ColumnarTranspositionC(userKey); encrypted = ctc.Encrypt(userInput); decrypted = ctc.Decrypt(userInput); } else { return; } break; case "ViGENERE": if (mTextBox.Text == "") { MessageBox.Show("Winegret text input is empty. Please type in something."); return; } if (validateVinegretKey(userKey) && validateVinegretWord(userInput)) { vig = new Vigenere(userKey); encrypted = vig.Encrypt(userInput); decrypted = vig.Decrypt(userInput); } else { return; } break; case "CEZAR": if (mTextBox.Text == "") { MessageBox.Show("Cezar text input is empty. Please type in something."); return; } if (validateCezarKey(userKey) && validateCezarWord(userInput)) { int i = int.Parse(userKey); cz = new Cezar(i); encrypted = cz.Encrypt(userInput); decrypted = cz.Decrypt(userInput); } else { return; } break; case "SYNC": if (syncFileName.Content.ToString() == " ") { MessageBox.Show("SYNC file input is empty. Please type in something."); return; } if (keyTextBox.Text == "") { MessageBox.Show("SYNC key text input is empty. Please type in something."); return; } if (!syncKeyGenerated) { MessageBox.Show("SYNC key needs to be generated first, please press run and then stop button before proceeding."); return; } normalDialog = false; synchronousStreamCipher = new SynchronousStreamCipher(lsfrGen.GetSequence()); TextWriter tw = new StreamWriter("LFSR KEY USED.txt"); List <bool> listOfBools = lsfrGen.GetSequence(); char boolOutcome = ' '; string boolOutcomeCollection = ""; int ij = 0; foreach (bool b in listOfBools) { if (b == true) { boolOutcome = '1'; } else { boolOutcome = '0'; } boolOutcomeCollection += boolOutcome; ij++; if (ij > 100) { ij = 0; tw.WriteLine(boolOutcomeCollection); boolOutcomeCollection = ""; } } tw.WriteLine(boolOutcomeCollection); tw.Close(); if (buttonName == "encrypt") { synchronousStreamCipher.Encrypt(syncFileName.Content.ToString()); } else { synchronousStreamCipher.Decrypt(syncFileName.Content.ToString()); } MessageBox.Show("Encrypted/decrypted file is located in folder where your .exe file is ( most probably bin/debug ). You will also find text file that contains LFSR key in it there."); break; case "DES": if (syncFileName.Content.ToString() == " ") { MessageBox.Show("DES file input is empty. Please type in something."); return; } if (keyTextBox.Text == "") { MessageBox.Show("DES key text input is empty. Please type in something."); return; } if (!validateDesKey(userKey)) { return; } des = new DES(desKeyParsing(userKey)); if (buttonName == "encrypt") { des.EncryptFile(syncFileName.Content.ToString()); } else { des.DecryptFile(syncFileName.Content.ToString()); } MessageBox.Show("Encrypted/decrypted file is located in folder where your .exe file is ( most probably bin/debug )."); break; default: break; } int length = encrypted.Length; outcomeLabel.FontSize = 30; if (length > 10) { outcomeLabel.FontSize = 20; } if (length > 20) { outcomeLabel.FontSize = 15; } if (normalDialog) { if (buttonName == "encrypt") { if (encrypted != "") { outcomeTypeLabel.Content = "Encrypted:"; } outcomeLabel.Content = encrypted; } else { if (decrypted != "") { outcomeTypeLabel.Content = "Decrypted:"; } outcomeLabel.Content = decrypted; } } else { } }