private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string text = CaesarAndVigenere.stripText(ciphertext).ToUpper(); results = Enigma.finalEnigma(text, rotorCount + 3, holdSize, plugCount, finalSize, this); Console.WriteLine("Done: " + results == null); }
private void runEncrypt() { Enigma enigma = makeEnigma(); if (enigma != null) { inputTextBox.Text = CaesarAndVigenere.stripText(inputTextBox.Text).ToUpper(); outputTextBox.Text = enigma.encrypt(inputTextBox.Text); } else { outputTextBox.Text = ""; } }
private void updateChart() { //chart1.Series["Actual Frequencies"].Points.DataBindY(CaesarAndVigenere.ALPHABET.ToArray()); chart1.Series["English Frequencies"].Enabled = false; chart1.Series["Actual Frequencies"].Enabled = false; chart1.Series["Frequencies of Caesar Decryption"].Enabled = false; string text = CaesarAndVigenere.stripText(parent.ciphertext); if (text.Length == 0) { return; } if (expectedFreqsCheckBox.Checked) { chart1.Series["English Frequencies"].Enabled = true; double[] percentageScores = CaesarAndVigenere.ENGLISH_FREQUENCIES.Select(x => 100.0 * x).ToArray(); chart1.Series["English Frequencies"].Points.DataBindY(percentageScores); } if (userCaesarShiftCheckBox.Checked) { if (!invalidKeyLabel.Visible) { chart1.Series["Frequencies of Caesar Decryption"].Enabled = true; double textLength = text.Length; int[] scores = CaesarAndVigenere.letterFrequencyAnalyser(CaesarAndVigenere.caesarText(text, caesarShiftLetterBox.Text[0], false)); double[] percentageScores = scores.Select(x => 100.0 * x / textLength).ToArray(); chart1.Series["Frequencies of Caesar Decryption"].Points.DataBindY(percentageScores); } } else { chart1.Series["Actual Frequencies"].Enabled = true; double textLength = text.Length; int[] scores = CaesarAndVigenere.letterFrequencyAnalyser(text); double[] percentageScores = scores.Select(x => 100.0 * x / textLength).ToArray(); chart1.Series["Actual Frequencies"].Points.DataBindY(percentageScores); } }
public void launchEncrypt(DataGridViewRow row, string text) { /*finalResultsDT.Columns.Add("Score", typeof(double)); * finalResultsDT.Columns.Add("Positions", typeof(string)); * finalResultsDT.Columns.Add("Rotors", typeof(string)); * finalResultsDT.Columns.Add("Rings", typeof(string)); * finalResultsDT.Columns.Add("Plugboard", typeof(string));*/ tabControl1.SelectTab(1); inputTextBox.Text = ""; // Positions leftPositionTB.Text = ((string)row.Cells[1].Value)[0].ToString(); midPositionTB.Text = ((string)row.Cells[1].Value)[1].ToString(); rightPositionTB.Text = ((string)row.Cells[1].Value)[2].ToString(); // Rings leftRingTB.Text = ((string)row.Cells[3].Value)[0].ToString(); midRingTB.Text = ((string)row.Cells[3].Value)[1].ToString(); rightRingTB.Text = ((string)row.Cells[3].Value)[2].ToString(); // Rotors leftRotorNumberCBox.SelectedIndex = (int)((string)row.Cells[2].Value)[0] - 49; midRotorNumberCBox.SelectedIndex = (int)((string)row.Cells[2].Value)[1] - 49; rightRotorNumberCBox.SelectedIndex = (int)((string)row.Cells[2].Value)[2] - 49; // Plugboard string plugs = CaesarAndVigenere.stripText((string)row.Cells[4].Value); for (int i = 0; i < plugs.Length / 2; i++) { plugBoardDGV.Rows[(int)plugs[2 * i] - 65].Cells[1].Value = plugs[2 * i + 1].ToString(); plugBoardDGV.Rows[(int)plugs[2 * i + 1] - 65].Cells[1].Value = plugs[2 * i].ToString(); } // Reflector reflectorCB.SelectedIndex = 1; inputTextBox.Text = text; runEncrypt(); this.Focus(); }
private void encryptButton_Click(object sender, EventArgs e) { ciphertext = CaesarAndVigenere.stripText(ciphertext); runEncrypt(caesarShiftLetterBox.Text[0], encryptRB.Checked); }
static void Main2() { using (StreamWriter file = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\output.txt")) { string hello = "ITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESS"; string hello2 = "LKWFLWYEGXVKOKMLDEXBWNAXMKVWTKVKOKMLDEXBWNAXMKVALXRWWNLGFMNMZRSYAHRGJHIWOTELJHSXVJ"; string[] m3rotors = new string[] { "EKMFLGDQVZNTOWYHXUSPAIBRCJ", "AJDKSIRUXBLHWTMCQGZNPYFVOE", "BDFHJLCPRTXVZNYEIWGAKMUSQO" }; //string reflectorB = "YRUHQSLDPXNGOKMIEBFZCWVJAT"; char[][] testKey = new char[][] { new char[] { 'A', 'B' }, new char[] { 'C', 'D' }, new char[] { 'E', 'F' } }; /*foreach (char item in reverseRotor(m3rotors[1])) * { * if (item != null) * file.Write(item + ", "); * else * file.Write("null, "); * }*/ Enigma e = new Enigma(new int[] { 1, 2, 3 }, 2, "LBJ", new char[][] { new char[] { 'A', 'D' }, new char[] { 'R', 'C' }, new char[] { 'L', 'M' }, new char[] { 'E', 'V' } }, "JFK"); string text2 = "TherewereakingwithalargejawandaqueenwithaplainfaceonthethroneofEnglandtherewereakingwithalargejawandaqueenwithafairfaceonthethroneofFranceInbothcountriesitwasclearerthancrystaltothelordsoftheStatepreservesofloavesandfishesthatthingsingeneralweresettledforeverItwastheyearofOurLordonethousandsevenhundredandseventyfiveSpiritualrevelationswereconcededtoEnglandatthatfavouredperiodasatthisMrsSouthcotthadrecentlyattainedherfiveandtwentiethblessedbirthdayofwhomapropheticprivateintheLifeGuardshadheraldedthesublimeappearancebyannouncingthatarrangementsweremadefortheswallowingupofLondonandWestminsterEventheCocklaneghosthadbeenlaidonlyarounddozenofyearsa"; file.WriteLine(e.encrypt(text2)); int[] pos = new int[] { 25, 17, 4 }; e = new Enigma(new int[] { 1, 2, 3 }, 2, pos, new char[][] { new char[] { 'A', 'D' }, new char[] { 'R', 'C' } }, new int[] { 0, 13, 13 }); //file.WriteLine(e.enigmaEncrypt("ITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESI")); //file.WriteLine("\n\n\n" + (new Enigma("123", 'B', "ARN", Enigma.PlugboardMaker("AD RC"), "QVA")).enigmaEncrypt("ITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESI")); //e.setRotors(new int[] { 3, 2, 1 }); //file.WriteLine(e.enigmaEncrypt("ITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESI")); // m3rotors, reflectorB, new char[] { 'S', 'D', 'T' }, new char[] { 'E', 'V' }, new char[][] { new char[] { 'A', 'D' }, new char[] { 'R', 'C' } }, new char[] { 'L', 'B', 'A' })); /*file.WriteLine("\n\n\n" + Enigma.sinkov("POETYRFFNTQYXAEXJOMUJQHFOCHEUUEWEXJUXDRZJTHGFQBIVDKXQQJTNQLNSRVXJDFPJQGIHIMEAPPMIJKUILPRNXHRIWXPUPVANONXQBMSQBJVLEFRMJUNTBVLXKNTASEWHYJCYMFGKUHGWWAIIZBVRZGSWKUFZYXVPWESKIBCUINBZLOKCPAEKSOODMHFEOMJYDMLFYGSWBSXXELMOTBBNLNAVLVAVWVEIWWMJAHNYLWFHRMYMXEWZKNQRJZQTCLCSLBIZEEJJOEMYMNOJNMKFDDYHQYTLTHRQYYPZQDYDXQXAJYRIWZNUDSGMXKCYYLYWQVMVFJDXVYOZMNUTANGDTOSPKZJQVKCSZXHKYECRZHVNNKDJVOIFGVKZCQKDJSAMCDEKWMONVEGFJTGTWTFTOTEEZPUPPCCUELBMTQXEJPFTCUAGRZZBGBVVGYQQP")); * file.WriteLine(Enigma.sinkov("ITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESI")); * file.WriteLine(Enigma.sinkov("TherewereakingwithalargejawandaqueenwithaplainfaceonthethroneofEnglandtherewereakingwithalargejawandaqueenwithafairfaceonthethroneofFranceInbothcountriesitwasclearerthancrystaltothelordsoftheStatepreservesofloavesandfishesthatthingsingeneralweresettledforeverItwastheyearofOurLordonethousandsevenhundredandseventyfiveSpiritualrevelationswereconcededtoEnglandatthatfavouredperiodasatthisMrsSouthcotthadrecentlyattainedherfiveandtwentiethblessedbirthda")); * Random random = new Random(); * file.WriteLine(Enigma.sinkov(new string(Enumerable.Repeat(ALPHABET, 450).Select(s => s[random.Next(s.Length)]).ToArray()))); */ e = new Enigma(new int[] { 1, 2, 3 }, 2, "ARN", new char[0][], "BNM"); //const string mysteryText = "WOYEPUCQSLMPXLLKNCIZPNTRBBIIXVBVOZREQHWBHEDNNOKNEICSNVKOPHEGUCRBHRYDSFSILPNEFIZFZSYFIZLXIORLNTSQPFSEGVCJZWOHNYRIZTLJSKHSUJQLYEFEMFXRRNWCOKRONSKIXKJRHBWRHLLRJONPPVHBEDOPSKTHCSVQGGSIQENSYKCZLICCCIVCCBBHFHZWNYNIDLWJVWOJGAYBDJBRGYGSJCNVQUFLVVVOPETPRGDNEIYHQVQNBTJEULIWHCDVCHSXCEIVSTGOXSQNRDLRNZPWKPQCPTKTYJMJVJJTPIXLDTVZQMTCJMEWJSEIPOVRXXDGGEXDTQTMMZMVFUPVOIEFSEVFBRWGTEEPZLSIBLEDQCRVDDHKJEQVAZRVKEDNERRPUMPNHAVZKTYVNWYPIZSQCOCTXOMDZGYMQNWOSSZVYLBGUWEDVYCFUISLFXTDQXSUXFHVJESFNVWWGKHGBJUEAGVCEBVEQZPSVGOKWOFHXXUSQWDZOSLVUHLUSPVYQDVDXBMHDBSEMVIFICTPBYZPECMKNCLSOAXCLMQTYMBHTXGTZTENULQFSCBXSFVXZAARFOVHHHXHVPTKILUQZQWDYLTCBXORHBAFUSZTQWJTJTOVKNKCOECAXDYOLP"; string mysteryText = "PNKZYMMHCJPGCEEQFAXKEKVJCZEZIEYCKBSMVLGCPKAERLPIIKCEFCBEVCHVYCUAJUKXAMPPMTMZHLDMDBQQRNRNTPJLEGBOGBUWEHNCYAGYFJSWPDVYDLWCTKCNLPLZTTKJUOBEPINPYEDMUNNLPTKBREMPIYIJDZFZBMPJCTSBBGDNAVNGMDJFHIIUENGBNGPFJPKKMCHSUWYCBVEIMYHBBCRIFPGATOOQGWYTPVYSEQNOTDSGIKPQKXJQZRUFDDJJPOIMECCWQCFEEKDCXWJZKLMKVRBAIGSQFYQCOVBTFKTRIIZAKBXFPDFHBOZVIGVIZBKSHCQWARHFAAKYGPKTELMZOVEPUTTRIUIZZVJKOHLSQKKAETAOHIDKYSSITNHHUTYESEEUSPMUFXLODQGWHJFCLUVBEJLYRXBKCWOIKFRSHDQEOZSXMZCETNQCXCRARVETEUBSCFXBHWMWTJBEZFDVCILZNCZVLWLXPLCAOSLGJMKGQFFDXYMNLDPGRDMSNXIUCZNCWRSUNERKNLXKTMSFTMRNLKWDAJFSRQJSKDHJRSFGGFRLHHDOFXYVVJJWJDJMPUMHUHZCRMVXCLFQUXNNBYYPYUJPECPRDGGZQVZOYYVVVILSEYRTNYXIROEAWPRSMR"; char[][] plugBoard = new char[][] { new char[] { 'A', 'D' }, new char[] { 'R', 'C' } }; int[][] results = Enigma.findBestRingSetting(new int[] { 1, 2, 3 }, new int[] { 25, 4, 1 }, mysteryText); string text = CaesarAndVigenere.stripText("TherewereakingwithalargejawandaqueenwithaplainfaceonthethroneofEnglandtherewereakingwithalargejawandaqueenwithafairfaceonthethroneofFranceInbothcountriesitwasclearerthancrystaltothelordsoftheStatepreservesofloavesandfishesthatthingsingeneralweresettledforeverItwastheyearofOurLordonethousandsevenhundredandseventyfiveSpiritualrevelationswereconcededtoEnglandatthatfavouredperiodasatthisMrsSouthcotthadrecentlyattainedherfiveandtwentiethblessedbirthdayofwhomapropheticprivateintheLifeGuardshadheraldedthesublimeappearancebyannouncingthatarrangementsweremadefortheswallowingupofLondonandWestminsterEventheCocklaneghosthadbeenlaidonlyarounddozenofyearsa").ToUpper(); file.WriteLine("Score of plaintext: " + Enigma.sinkov(text)); text = Regex.Replace(text, Char.ToString('A'), Char.ToString('d')); text = Regex.Replace(text, Char.ToString('D'), Char.ToString('a')); text = Regex.Replace(text, Char.ToString('R'), Char.ToString('c')); text = Regex.Replace(text, Char.ToString('C'), Char.ToString('r')); text = text.ToUpper(); /*file.WriteLine("Score of plugged plaintext from python: " + Enigma.sinkov("THECEWQCEDKINGWITYDLDCGWJDWDNADQUEXNWITHDPKDINFDREJNTHETHCONEVUENVLANATHECEWECEDKINGWITHDLKCGEJDWDNADQFEENWITHTFDICFDREONTHETHCONEOOTCDGREZNBOTHROUKTCIPSITODSRLEDCECJHDNRCYVTDLTOTHELOCASGFTHZYMDTDICESECVESOFLGDVESDNAFQSHOSTGDTTHIFGSINGENECDLWECYSXTTLEAFOCEVECITWDSTUKYXDCOZOUCLOCAONETSTUYDNASEVEIHUNACEADNASEVENTRFIVESPLCITUDLCEVELGTIGNSWEJERONREAEATOENGLDNADTTODTFDVOUCEAPECCOWISAPTHISMCOSZUTHFOTJWDACEREITLYDTTDINEAHECBIOEDNAZWENTIETHBLESSEABICTGADIOFWHOMDPQOPHETIRPCIVDTEINTHELIFEGHDCOSHDAHECDLAEATHESUBLIMEAPPEDCDNREBYDNNSUPRINGFHDTDCCDNLEMENTSWNCEMZAEFHCPHESWDLLOWINGUPOFLONAOMDNAWESTSTTSTECEVENTHERORKLDNEBHOSBHDAOEEOLDIAONLYDCOUNAAOHENLQYIDCSD")); * file.WriteLine("Score of plugged plaintext from C#: " + Enigma.sinkov(e.encrypt("THECEWQCEDKINGWITYDLDCGWJDWDNADQUEXNWITHDPKDINFDREJNTHETHCONEVUENVLANATHECEWECEDKINGWITHDLKCGEJDWDNADQFEENWITHTFDICFDREONTHETHCONEOOTCDGREZNBOTHROUKTCIPSITODSRLEDCECJHDNRCYVTDLTOTHELOCASGFTHZYMDTDICESECVESOFLGDVESDNAFQSHOSTGDTTHIFGSINGENECDLWECYSXTTLEAFOCEVECITWDSTUKYXDCOZOUCLOCAONETSTUYDNASEVEIHUNACEADNASEVENTRFIVESPLCITUDLCEVELGTIGNSWEJERONREAEATOENGLDNADTTODTFDVOUCEAPECCOWISAPTHISMCOSZUTHFOTJWDACEREITLYDTTDINEAHECBIOEDNAZWENTIETHBLESSEABICTGADIOFWHOMDPQOPHETIRPCIVDTEINTHELIFEGHDCOSHDAHECDLAEATHESUBLIMEAPPEDCDNREBYDNNSUPRINGFHDTDCCDNLEMENTSWNCEMZAEFHCPHESWDLLOWINGUPOFLONAOMDNAWESTSTTSTECEVENTHERORKLDNEBHOSBHDAOEEOLDIAONLYDCOUNAAOHENLQYIDCSD"))); */ file.WriteLine("Positions: [" + results[0][0] + ", " + results[0][1] + ", " + results[0][2] + "] " + "Rings: [" + results[1][0] + ", " + results[1][1] + ", " + results[1][2] + "] "); System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); //DataRow[] dRows = Enigma.findBestRotors(mysteryText, 3, 1000); //DataTable dt = Enigma.breakEnigma(mysteryText, 3, 10, 2); DataTable dt = Enigma.finalEnigma(mysteryText, 3, 100, 4, 10); DataRow[] dr = new DataRow[10]; Array.Copy(dt.Select("", "Score DESC"), dr, 10); //DataRow[] dr = Enigma.finalEnigma(mysteryText, 3, 100, 4, 10); //DataTable dt = Enigma.findRingsAndRotors(mysteryText, 3, 100); /*char[][] plugs = (Enigma.findPlugboard(mysteryText, new int[] { 1, 2, 3 }, new int[] { 25, 17, 14 }, * new int[] { 0, 13, 13 }, 2)); * StringBuilder sb = new StringBuilder(); * foreach (char[] plug in plugs) * { * sb.Append("[" + plug[0] + ", " + plug[1] + "], "); * } * sb.Remove(sb.Length - 1, 1); * file.WriteLine("Plugs found: " + sb.ToString());*/ //Enigma.sinkov("ITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESITWASTHEAGEOFWISDOMITWASTHEAGEOFFOOLISHNESSITWASTHEBESTOFTIMESITWASTHEWORSTOFTIMESI"); watch.Stop(); long elapsedMs = watch.ElapsedMilliseconds; file.WriteLine((double)elapsedMs / 1000.0); Enigma f = new Enigma(new int[] { 1, 2, 3 }, 2, "ARN", new char[][] { new char[] { 'A', 'D' }, new char[] { 'R', 'C' } }, "QVA"); file.WriteLine("Answer: [" + f.rotorPositions[0] + ", " + f.rotorPositions[1] + ", " + f.rotorPositions[2] + "]\n"); //foreach (DataRow row in dt.Select()) foreach (DataRow row in dr) { int[] positions = row.Field <int[]>(1); int[] rotors = row.Field <int[]>(2); int[] rings = row.Field <int[]>(3); char[][] plugs2 = row.Field <char[][]>(4); //char[][] plugs = new char[0][]; //if (positions[0] == 25) // if (positions[1] == 4) // if (positions[2] == 1) // file.Write("Found it!: "); Enigma s = new Enigma(rotors, 2, positions, plugs2, rings); file.WriteLine(s.ToString() + " Score: " + row.Field <double>(0)); //file.WriteLine("Position: [" + positions[0] + ", " + positions[1] + ", " + positions[2] + "], Rotors: [" + // rotors[0] + ", " + rotors[1] + ", " + rotors[2] + "], Rings: ["+ rings[0] + ", " + rings[1] + ", " + // rings[2] + "] Old Score: " + row.Field<double>(0)); } } }
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progressBar1.Value = 0; string text = CaesarAndVigenere.stripText(ciphertext).ToUpper(); int finalSize = holdSize / 2; if (finalSize == 0) { finalSize = 1; } numOfEncryptions = Enigma.numOfEncryptionsToBreak(rotorCountCB.SelectedIndex + 3, Int32.Parse(initHoldSizeTB.Text), Int32.Parse(plugNumberTB.Text), finalSize); //System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); //watch.Stop(); //long elapsedMs = watch.ElapsedMilliseconds; //Console.WriteLine((double)elapsedMs/1000.0); /* dt.Columns.Add("Score", typeof(double)); * dt.Columns.Add("Positions", typeof(int[])); * dt.Columns.Add("Rotors", typeof(int[])); * dt.Columns.Add("Rings", typeof(int[])); * dt.Columns.Add("Plugboard", typeof(char[][])); */ DataTable finalResultsDT = new DataTable(); finalResultsDT.Columns.Add("Score", typeof(double)); finalResultsDT.Columns.Add("Positions", typeof(string)); finalResultsDT.Columns.Add("Rotors", typeof(string)); finalResultsDT.Columns.Add("Rings", typeof(string)); finalResultsDT.Columns.Add("Plugboard", typeof(string)); finalResultsDT.Columns.Add("Text", typeof(string)); foreach (DataRow row in results.Rows) { DataRow newRow = finalResultsDT.NewRow(); newRow[0] = row[0]; newRow[1] = new string(((int[])row[1]).Select(x => (char)(x + 65)).ToArray()); newRow[2] = new string(((int[])row[2]).Select(x => (char)(x + 48)).ToArray()); newRow[3] = new string(((int[])row[3]).Select(x => (char)(x + 65)).ToArray()); StringBuilder plugBoard = new StringBuilder(); foreach (char[] plug in (char[][])row[4]) { plugBoard.Append('[').Append(plug[0]).Append(", ").Append(plug[1]).Append("] "); } newRow[4] = plugBoard.ToString(); newRow[5] = (new Enigma((string)newRow[2], 'B', (string)newRow[1], (char[][])((char[][])row[4]).Clone(), (string)newRow[3])).encrypt(text); finalResultsDT.Rows.Add(newRow); } dataGridView1.DataSource = null; dataGridView1.DataSource = finalResultsDT; dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending); dataGridView1.Columns["Text"].Width = 250; }
private void encryptButton_Click(object sender, EventArgs e) { ciphertext = CaesarAndVigenere.stripText(ciphertext); runEncrypt(CaesarAndVigenere.stripText(keyTextBox.Text).ToUpper(), encryptRB.Checked); }