source: trunk/CrypPlugins/VigenereAutokeyAnalyser/VigenereAutokeyAnalyserSettings.cs @ 2334

Last change on this file since 2334 was 2334, checked in by Matthäus Wander, 11 years ago

removed 1006 occurences of DisplayLevel in 218 files (see #122)

File size: 5.4 KB
Line 
1/* HOWTO: Change year, author name and organization.
2   Copyright 2010 Your Name, University of Duckburg
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*/
16using System;
17using System.Collections.Generic;
18using System.Linq;
19using System.Text;
20using Cryptool.PluginBase;
21using System.ComponentModel;
22
23namespace Cryptool.Plugins.VigenereAutokeyAnalyser
24{
25    public class VigenereAutokeyAnalyserSettings : ISettings
26    {
27        #region Private Variables
28
29        private bool hasChanges = false;
30        private int language = 0;                                   //Set the expected language (0: English ; 1: German ; 2: French ; 3: Spain)
31        private int modus = 0;                                      //Set the modus (0: Autokey ; 1: Original Vigenere)
32        private String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";     //The standard configuration
33
34        #endregion
35
36        #region TaskPane Settings
37
38        /// <summary>
39        /// Choose the modus to work with
40        /// </summary>
41        [ContextMenu("Modus", "Select the modus you want to work with", 2, ContextMenuControlType.ComboBox, null, new String[] { "Autokey", "Vigenere" })]
42        [TaskPane("Modus", "Select the modus you want to work with", null, 2, false, ControlType.ComboBox, new String[] { "Autokey", "Vigenere" })]
43        public int Modus // Autokey or Repeatedkey
44        {
45            get { return this.modus; }
46            set
47            {
48                if (((int)value) != modus) hasChanges = true;
49                this.modus = (int)value;
50                OnPropertyChanged("Modus");
51            }
52        }
53
54        /// <summary>
55        /// Choose the language frequency to work with
56        /// </summary>
57        [ContextMenu("Expected Language", "Select the language you expect the plaintext to be", 2, ContextMenuControlType.ComboBox, null, new String[] { "English", "German", "French", "Spanish" })]
58        [TaskPane("Expected Language", "Select the language you expect the plaintext to be", null, 2, false, ControlType.ComboBox, new String[] { "English", "German", "French", "Spanish" })]
59        public int Language // Expected letter frequencies
60        {
61            get { return this.language; }
62            set
63            {
64                if (((int)value) != language) hasChanges = true;
65                this.language = (int)value;
66                OnPropertyChanged("Language");
67            }
68        }
69
70        /// <summary>
71        /// Choose the alphabet letters to work with
72        /// </summary>
73        [TaskPane("Alphabet", "This is the used alphabet.", null, 7, false, ControlType.TextBox, null)]
74        public string AlphabetSymbols
75        {
76            get { return this.alphabet; }
77            set
78            {
79                string a = removeEqualChars(value);     //removes all char that are used twice in the alphabet
80
81                if (a.Length == 0)                      //cannot accept empty alphabets and will just use the standard;
82                {
83                   
84                }
85                else if (!alphabet.Equals(a))
86                {
87                    hasChanges = true;
88                    this.alphabet = a;
89                    OnPropertyChanged("AlphabetSymbols");
90                }
91            }
92        }
93
94        #endregion
95
96        #region ISettings Members
97
98        /// <summary>
99        /// HOWTO: This flags indicates whether some setting has been changed since the last save.
100        /// If a property was changed, this becomes true, hence CrypTool will ask automatically if you want to save your changes.
101        /// </summary>
102        public bool HasChanges
103        {
104            get
105            {
106                return hasChanges;
107            }
108            set
109            {
110                hasChanges = value;
111            }
112        }
113
114        #endregion
115
116        #region Private methods
117
118        /// <summary>
119        /// Removes all the letters in the provided alphabet that are used twice
120        /// </summary>
121        private string removeEqualChars(string value)
122        {
123            int length = value.Length;
124
125            for (int i = 0; i < length; i++)
126            {
127                for (int j = i + 1; j < length; j++)
128                {
129                    if ((value[i]) == (value[j]))
130                    {                       
131                        value = value.Remove(j, 1);
132                        j--;
133                        length--;
134                    }
135                }
136            }
137            return value;
138        }
139
140        #endregion
141
142        #region INotifyPropertyChanged Members
143
144        public event PropertyChangedEventHandler PropertyChanged;
145
146        protected void OnPropertyChanged(string name)
147        {
148            if (PropertyChanged != null)
149            {
150                PropertyChanged(this, new PropertyChangedEventArgs(name));
151            }
152        }
153
154
155        #endregion
156    }
157}
Note: See TracBrowser for help on using the repository browser.