Changeset 1664


Ignore:
Timestamp:
Jun 17, 2010, 2:05:25 PM (12 years ago)
Author:
nolte
Message:

Added a Key Choice options to the Vigenere AutokeyAnalyser Quickview...the best key is still autoselected but now
the user can try out all other possible keys by double click them

Location:
trunk/CrypPlugins/VigenereAutokeyAnalyser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/VigenereAutokeyAnalyser/AutokeyPresentation.xaml.cs

    r1661 r1664  
    1313using System.Windows.Shapes;
    1414using System.Collections.ObjectModel;
     15using System.Windows.Threading;
     16using System.Threading;
    1517
    1618namespace VigenereAutokeyAnalyser
     
    2224    {
    2325        public ObservableCollection<ResultEntry> entries = new ObservableCollection<ResultEntry>();
     26        public event MouseButtonEventHandler SelectedIndexChanged;
    2427
    2528        public AutokeyPresentation()
    2629        {
    2730            InitializeComponent();
    28             SizeChanged += sizeChanged;
     31            SizeChanged += new SizeChangedEventHandler(AutokeyPresentation_SizeChanged);
     32            ListView.MouseDoubleClick += new MouseButtonEventHandler(ListView_MouseDoubleClick);
    2933            this.DataContext = entries;
    3034            entries.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(entries_CollectionChanged);
     35        }
     36
     37        void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
     38        {
     39            if (SelectedIndexChanged != null)
     40            {
     41                SelectedIndexChanged(sender, e);
     42            }
     43        }
     44
     45        private void AutokeyPresentation_SizeChanged(object sender, SizeChangedEventArgs e)
     46        {
     47            updateScaling();
    3148        }
    3249
     
    6986        }
    7087
    71         private void sizeChanged(Object sender, EventArgs eventArgs)
    72         {
    73 
    74             updateScaling();
    75            
    76             //Console.WriteLine("Width: {0}, Heigth: {1}; GridWith: {2}, GridHeight: {3}", this.Width, this.Height, this.Grid.Width, this.Grid.Height);
    77             //Console.WriteLine("Actual- Width: {0}, Heigth: {1}; GridWith: {2}, GridHeight: {3}", this.ActualWidth, this.ActualHeight, this.Grid.ActualWidth, this.Grid.ActualHeight);
    78             //Console.WriteLine("ListViewWidth: {0}, ListViewHeigth: {1}; ActualListViewWith: {2}, ActualListViewHeight: {3}", this.ListView.Width, this.ListView.Height, this.ListView.ActualWidth, this.ListView.ActualHeight);
    79         }
    80 
    81 
    8288        private void updateScaling()
    8389        {
     
    8591            this.scaler.ScaleY = this.scaler.ScaleX;
    8692        }
     93
     94        public void selectIndex(int index)
     95        {
     96            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     97            {
     98                ListView.SelectedIndex = index;
     99
     100            }, null);
     101
     102           
     103        }
     104
     105        public void Add(ResultEntry item)
     106        {
     107            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     108            {
     109                entries.Add(item);
     110
     111            }, null);
     112           
     113        }
     114
     115        public void Clear()
     116        {
     117            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     118            {
     119                entries.Clear();
     120           
     121            }, null);
     122        }
     123       
     124       
    87125    }
    88126}
  • trunk/CrypPlugins/VigenereAutokeyAnalyser/VigenereAutokeyAnalyser.cs

    r1661 r1664  
    2727using System.Windows.Threading;
    2828using System.Threading;
     29using System.Windows.Input;
    2930
    3031namespace Cryptool.Plugins.VigenereAutokeyAnalyser
     
    3738        #region Private Variables
    3839
    39         private readonly VigenereAutokeyAnalyserSettings settings = new VigenereAutokeyAnalyserSettings();
    40         private UserControl quickWatchPresentation = new AutokeyPresentation();     //The Quickwatch to be used
     40        private readonly VigenereAutokeyAnalyserSettings settings;
     41        private AutokeyPresentation quickWatchPresentation;         //The Quickwatch to be used
    4142
    4243        private String ciphertext = "";                             //The cipher to be analysed
     
    141142        #region IPlugin Members
    142143
     144        public VigenereAutokeyAnalyser()
     145        {
     146            settings = new VigenereAutokeyAnalyserSettings();
     147            quickWatchPresentation = new AutokeyPresentation();
     148            quickWatchPresentation.SelectedIndexChanged += new MouseButtonEventHandler(quickWatchPresentation_SelectedIndexChanged);
     149        }
     150
    143151        public ISettings Settings
    144152        {
     
    167175            ProgressChanged(0, 1);
    168176
    169             ((AutokeyPresentation)Presentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    170             {
    171                 ((AutokeyPresentation)Presentation).entries.Clear();
    172             }, null);
    173            
     177            quickWatchPresentation.Clear();
     178           
    174179            alphabet = settings.AlphabetSymbols;                //initialising the alphabet as given by the user       
    175180
     
    215220                    breakVigenereAutoKey(d);                    //"BREAK VIGENERE AUTO KEY(KEYLENGTH)" IS THE MAIN METHODE IN FINDING THE KEY FOR A GIVEN KEYLENGTH
    216221                }                                               //(-> see private methods section)
    217             } 
    218                        
     222            }
     223
     224            quickWatchPresentation.selectIndex((finalkey.Length) - 1);
     225
    219226            OutputKey = finalkey;                               //sending the key via output
    220227            OnPropertyChanged("OutputKey");
     
    476483        private void showResult(String key, double IC)
    477484        {
    478             ((AutokeyPresentation)Presentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    479             {
    480485                ResultEntry entry = new ResultEntry();
    481486                entry.Key = key;
    482487                entry.IC = IC.ToString();
    483488
    484                 ((AutokeyPresentation)Presentation).entries.Add(entry);
    485 
    486             }, null);
    487 
     489                quickWatchPresentation.Add(entry);
     490        }
     491
     492//-----------------------------------------------------------------------------------------------------------------------------------------
     493//PRESENTATION UPDATE----------------------------------------------------------------------------------------------------------------------
     494
     495        void quickWatchPresentation_SelectedIndexChanged(object sender, MouseButtonEventArgs e)
     496        {
     497            ListView lv = sender as ListView;
     498            if (lv != null)
     499            {
     500                ResultEntry rse = lv.SelectedItem as ResultEntry;
     501
     502                if (rse != null)
     503                {
     504                    OutputKey = rse.Key;
     505                    OnPropertyChanged("OutputKey");
     506                }
     507            }
    488508        }
    489509
     
    546566                {
    547567                    finalIC = IC;                                       //remember the IC
    548                     finalkey = key;                                     //remember the key
     568                    finalkey = key;                                     //remember the key                                     
    549569                }
    550570
Note: See TracChangeset for help on using the changeset viewer.