source: trunk/CrypPlugins/CostFunction/CostFunctionSettings.cs @ 1375

Last change on this file since 1375 was 1375, checked in by malischewski, 12 years ago

Started implementation of new costfunction for genetic algorithm analysis of transposition cipher.
note: is listed as "weighted bigrams/trigrams" in the plugin, but not functional yet (will be tomorrow, probably)

File size: 4.4 KB
Line 
1/*                             
2   Copyright 2009 Team CrypTool (Sven Rech,Dennis Nolte,Raoul Falk,Nils Kopal), Uni Duisburg-Essen
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.ComponentModel;
22using Cryptool.PluginBase;
23using System.Collections.ObjectModel;
24using System.Windows;
25
26namespace Cryptool.Plugins.CostFunction
27{
28    class CostFunctionSettings : ISettings
29    {
30        #region private variables
31        private bool hasChanges = false;
32        private int functionType;
33        private String bytesToUse = "256";
34        private int bytesToUseInteger = 256;
35        #endregion
36       
37        [TaskPane("FunctionType", "Select the type of function", null, 1, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "Index of coincidence", "Entropy", "Bigrams: log 2", "Bigrams: Sinkov", "Bigrams: Percentaged", "Regular Expression", "Weighted Bigrams/Trigrams"})]
38        public int FunctionType
39        {
40            get { return this.functionType; }
41            set
42            {
43                this.functionType = (int)value;
44                UpdateTaskPaneVisibility();
45                OnPropertyChanged("FunctionType");
46            }
47        }
48
49        [TaskPane("Bytes to use", "Which amount of bytes should be used for calculating?", null, 4, false, DisplayLevel.Beginner, ControlType.TextBox)]
50        public String BytesToUse
51        {
52            get
53            {
54                return bytesToUse;
55            }
56            set
57            {
58                bytesToUse = value;
59                bytesToUseInteger = int.Parse(value);
60                OnPropertyChanged("BytesToUse");
61            }
62        }
63
64        public int BytesToUseInteger
65        {
66            get { return bytesToUseInteger; }
67        }
68
69        public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
70
71        internal void UpdateTaskPaneVisibility()
72        {
73            if (TaskPaneAttributeChanged == null)
74            {
75                return;
76            }
77
78            if (functionType.Equals(5))
79            {
80                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BytesToUse", Visibility.Visible)));
81                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("RegEx", Visibility.Visible)));
82            }
83            else
84            {
85                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BytesToUse", Visibility.Visible)));
86                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("RegEx", Visibility.Collapsed)));
87            }
88
89        }
90
91
92        private string regEx;
93        [TaskPane("Regular Expression:", "Regular Expression match", null, 5, false, DisplayLevel.Beginner, ControlType.TextBox)]
94        public String RegEx
95        {
96            get
97            {
98                return regEx;
99            }
100            set
101            {
102                regEx = value;
103                OnPropertyChanged("RegEx");
104            }
105        }
106
107        #region ISettings Members
108
109        public bool HasChanges
110        {
111            get
112            {
113                return hasChanges;
114            }
115            set
116            {
117                hasChanges = value;
118            }
119        }
120
121        #endregion
122
123        #region INotifyPropertyChanged Members
124
125        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
126
127        private void OnPropertyChanged(string p)
128        {
129            if (PropertyChanged != null)
130            {
131                PropertyChanged(this, new PropertyChangedEventArgs(p));
132            }
133        }
134
135        #endregion
136    }
137   
138   
139}
Note: See TracBrowser for help on using the repository browser.