Example #1
0
 string entryToText(ResultEntry entry)
 {
     return("Rank: " + entry.Ranking + Environment.NewLine +
            "Value: " + entry.ExactValue + Environment.NewLine +
            "Key: " + entry.Key + Environment.NewLine +
            "KeyLength: " + entry.KeyLength + Environment.NewLine +
            "Text: " + removeNuls(entry.Text));
 }
Example #2
0
        /// <summary>
        /// Adds an entry to the BestList
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="ciphertext"></param>
        private void AddNewBestListEntry(int[] key, double value, int[] ciphertext)
        {
            var entry = new ResultEntry
            {
                Key  = MapNumbersIntoTextSpace(key, Alphabet),
                Text = MapNumbersIntoTextSpace(_settings.Mode == Mode.Vigenere ? DecryptVigenereOwnAlphabet(ciphertext, key, MapTextIntoNumberSpace(VigenereAlphabet, Alphabet)) :
                                               DecryptAutokeyOwnAlphabet(ciphertext, key, MapTextIntoNumberSpace(VigenereAlphabet, Alphabet)), Alphabet),
                Value = value
            };

            if (_presentation.BestList.Count == 0)
            {
                Plaintext = entry.Text;
                Key       = entry.Key;
            }
            else if (entry.Value > _presentation.BestList.First().Value)
            {
                Plaintext = entry.Text;
                Key       = entry.Key;
            }

            Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate
            {
                try
                {
                    if (_presentation.BestList.Count > 0 && entry.Value <= _presentation.BestList.Last().Value)
                    {
                        return;
                    }
                    _presentation.BestList.Add(entry);
                    _presentation.BestList = new ObservableCollection <ResultEntry>(_presentation.BestList.OrderByDescending(i => i.Value));
                    if (_presentation.BestList.Count > MaxBestListEntries)
                    {
                        _presentation.BestList.RemoveAt(MaxBestListEntries);
                    }
                    var ranking = 1;
                    foreach (var e in _presentation.BestList)
                    {
                        e.Ranking = ranking;
                        ranking++;
                    }
                    _presentation.ListView.DataContext = _presentation.BestList;
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception)
                {
                    //wtf?
                }
            }, null);
        }
Example #3
0
        public void ContextMenuHandler(Object sender, EventArgs eventArgs)
        {
            try
            {
                MenuItem    menu  = (MenuItem)((RoutedEventArgs)eventArgs).Source;
                ResultEntry entry = (ResultEntry)menu.CommandParameter;
                if (entry == null)
                {
                    return;
                }
                string tag = (string)menu.Tag;

                if (tag == "copy_text")
                {
                    Clipboard.SetText(removeNuls(entry.Text));
                }
                else if (tag == "copy_value")
                {
                    Clipboard.SetText("" + entry.Value);
                }
                else if (tag == "copy_key")
                {
                    Clipboard.SetText(entry.Key);
                }
                else if (tag == "copy_line")
                {
                    Clipboard.SetText(entryToText(entry));
                }
                else if (tag == "copy_all")
                {
                    List <string> lines = new List <string>();
                    foreach (var e in BestList)
                    {
                        lines.Add(entryToText(e));
                    }
                    Clipboard.SetText(String.Join(Environment.NewLine, lines));
                }
            }
            catch (Exception ex)
            {
                Clipboard.SetText("");
            }
        }