示例#1
0
 string entryToText(ResultEntry entry)
 {
     return("Rank: " + entry.Ranking + "\n" +
            "Value: " + entry.Value + "\n" +
            "Attack: " + entry.Attack + "\n" +
            "Key: " + entry.Key + "\n" +
            "Text: " + removeNuls(entry.Text));
 }
示例#2
0
        public void HandleDoubleClick(Object sender, EventArgs eventArgs)
        {
            ListViewItem lvi = sender as ListViewItem;
            ResultEntry  r   = lvi.Content as ResultEntry;

            if (r != null)
            {
                this.updateOutputFromUserChoice(r.Key, r.Text);
            }
        }
示例#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 entries)
                    {
                        lines.Add(entryToText(e));
                    }
                    Clipboard.SetText(String.Join("\n\n", lines));
                }
            }
            catch (Exception ex)
            {
                Clipboard.SetText("");
            }
        }
示例#4
0
        private void UpdateKeyDisplay(KeyCandidate keyCan)
        {
            try
            {
                bool update = false;

                // Add key if key does not already exists
                if (!this.keyCandidates.Contains(keyCan))
                {
                    this.keyCandidates.Add(keyCan);
                    this.keyCandidates.Sort(new KeyCandidateComparer());

                    if (this.keyCandidates.Count > 20)
                    {
                        this.keyCandidates.RemoveAt(this.keyCandidates.Count - 1);
                    }
                    update = true;
                }
                else
                {
                    int          index = this.keyCandidates.IndexOf(keyCan);
                    KeyCandidate keyCanAlreadyInList = this.keyCandidates[index];
                    if (keyCan.DicAttack == true)
                    {
                        if (keyCanAlreadyInList.DicAttack == false)
                        {
                            keyCanAlreadyInList.DicAttack = true;
                            update = true;
                        }
                    }
                    if (keyCan.GenAttack == true)
                    {
                        if (keyCanAlreadyInList.GenAttack == false)
                        {
                            keyCanAlreadyInList.GenAttack = true;
                            update = true;
                        }
                    }
                }

                // Display output
                if (update)
                {
                    this.plaintext = this.keyCandidates[0].Plaintext;
                    OnPropertyChanged("Plaintext");

                    this.plaintext_alphabet_output = CreateAlphabetOutput(this.keyCandidates[0].Key, this.ctAlphabet);
                    OnPropertyChanged("Plaintext_Alphabet_Output");

                    ((AssignmentPresentation)Presentation).Dispatcher.Invoke(DispatcherPriority.Normal,
                                                                             (SendOrPostCallback) delegate
                    {
                        try
                        {
                            ((AssignmentPresentation)Presentation).entries.Clear();

                            for (int i = 0; i < this.keyCandidates.Count; i++)
                            {
                                KeyCandidate keyCandidate = this.keyCandidates[i];

                                ResultEntry entry = new ResultEntry();
                                entry.Ranking     = i.ToString();
                                entry.Text        = keyCandidate.Plaintext;
                                entry.Key         = keyCandidate.Key_string;

                                if (keyCandidate.GenAttack == true && keyCandidate.DicAttack == false)
                                {
                                    entry.Attack = Resources.GenAttackDisplay;
                                }
                                else if (keyCandidate.DicAttack == true && keyCandidate.GenAttack == false)
                                {
                                    entry.Attack = Resources.DicAttackDisplay;
                                }
                                else if (keyCandidate.GenAttack == true && keyCandidate.DicAttack == true)
                                {
                                    entry.Attack = Resources.GenAttackDisplay + ", " + Resources.DicAttackDisplay;
                                }

                                double f    = Math.Log10(Math.Abs(keyCandidate.Fitness));
                                entry.Value = string.Format("{0:0.00000} ", f);
                                ((AssignmentPresentation)Presentation).entries.Add(entry);
                            }
                        }
                        catch (Exception ex)
                        {
                            GuiLogMessage("Exception during UpdateKeyDisplay Presentation.Dispatcher: " + ex.Message, NotificationLevel.Error);
                        }
                    }, null);
                }
            }
            catch (Exception ex)
            {
                GuiLogMessage("Exception during UpdateKeyDisplay: " + ex.Message, NotificationLevel.Error);
            }
        }