Ignore:
Timestamp:
Jun 14, 2010, 12:58:52 PM (12 years ago)
Author:
nolte
Message:

Modified the code of both Plugins (Vigenere Autokey Analyser & AutokorrelationFunction )...
know they can be read more comfortable.

Location:
trunk/CrypPlugins/AutokorrelationFunction
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/AutokorrelationFunction/AutokorrelationFunction.cs

    r1623 r1633  
    4040        private double probablekorr = -999999.999999;                   //initialized probable korrelation of the length
    4141        private String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";         //used alphabet
    42         private double a;                                               //Found same letter counter
     42        private double same;                                            //Found same letter counter
    4343        private double[] ak;                                            // Autokorrelation Values
    4444
     
    4747        #region Data Properties
    4848
     49        /// <summary>
     50        /// The input for the ciphertext
     51        /// </summary>
    4952        [PropertyInfo(Direction.InputData, "Cipher Input", "Enter your cipher here", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    5053        public String InputCipher
     
    6164        }
    6265
     66        /// <summary>
     67        /// The output for the found shift value (most probable keylength)
     68        /// </summary>
    6369        [PropertyInfo(Direction.OutputData, "Keylength Output", "The most probable keylength for the analysed ciphertext", "", DisplayLevel.Beginner)]
    6470        public int OutputLength
     
    8490        }
    8591
    86         /// <summary>
    87         /// HOWTO: You can provide a custom (tabbed) presentation to visualize your algorithm.
    88         /// Return null if you don't provide one.
    89         /// </summary>
    9092        public UserControl Presentation
    9193        {
     
    9395        }
    9496
    95         /// <summary>
    96         /// HOWTO: You can provide custom (quickwatch) presentation to visualize your algorithm.
    97         /// Return null if you don't provide one.
    98         /// </summary>
    9997        public UserControl QuickWatchPresentation
    10098        {
     
    106104        }
    107105
    108         /// <summary>
    109         /// HOWTO: Enter the algorithm you'd like to implement in this method.
    110         /// </summary>
    111106        public void Execute()
    112107        {
    113            
     108
     109//START------------------------------------------------------------------------------------------------------------
     110//Preparations for the Analyse-------------------------------------------------------------------------------------
     111           
    114112            ProgressChanged(0, 1);
    115113
    116 //-------------------------------------------------------------------------------------------------------------------------
    117 
    118             cipher = InputCipher;
    119             cipher = prepareForAnalyse(cipher);
    120 
    121             ak = new double[cipher.Length];
    122                
     114            cipher = InputCipher;                               //initialising the ciphertext
     115            cipher = prepareForAnalyse(cipher);                 //and prepare it for the analyse (-> see private methods section)
     116
     117            ak = new double[cipher.Length];                     //initialise ak[]...there are n possible shifts where n is cipher.length
     118
     119//-----------------------------------------------------------------------------------------------------------------
     120//Analyse----------------------------------------------------------------------------------------------------------
     121//-----------------------------------------------------------------------------------------------------------------             
     122
     123            //for each possible shift value...
    123124                    for(int t=0; t<cipher.Length; t++)
    124125                    {
    125                             a=0;
     126                            same=0;
    126127                       
     128                //...calculate how often the letters match...
    127129                            for(int x=0; x<cipher.Length-t;x++)
    128130                            {
    129131                                    if(cipher[x] == cipher[x+t])
    130132                                    {
    131                                             a++;
     133                                            same++;
    132134                                    }
    133135                            }
    134136                       
    135                             ak[t] = a;
     137                //...and save the count for the matches at the shift position
     138                            ak[t] = same;
    136139                    }
    137140               
     141            //For all observed shifts...
    138142                    for(int y=1;y<ak.Length;y++)
    139143                    {
     144                //find the one with the highest match count...
    140145                            if(ak[y] > probablekorr)
    141146                            {
    142147                                    probablekorr = ak[y];
    143                                     probablelength = y;
     148                    probablelength = y;                 //...and remember this shift value
    144149                            }
    145150                    }
    146151
    147             OutputLength = probablelength;
     152            OutputLength = probablelength;              //sending the keylength via output
    148153            OnPropertyChanged("OutputLength");         
    149154                   
    150 //-------------------------------------------------------------------------------------------------------------------------
     155
    151156
    152157            ProgressChanged(1, 1);
     158
     159//EXECUTE END------------------------------------------------------------------------------------------------------
     160       
    153161        }
    154162
     
    179187//PREPARE PART---------------------------------------------------------------------------------------------------------------------------
    180188
     189        /// <summary>
     190        /// Remove spaces and symbols not provided by the alphabet from the text
     191        /// </summary>
    181192        private String prepareForAnalyse(String c)
    182193        {
     
    196207
    197208
    198 
    199209//---------------------------------------------------------------------------------------------------------------------------------------
    200210//LETTER TO NUMBER----------------------------------------------------------------------------------------------------------------------
    201211
     212        /// <summary>
     213        /// Convert a the letter to an int-value that resembles his position in the given alphabet
     214        /// </summary>
    202215        private int getPos(char c)
    203216        {
     
    215228//---------------------------------------------------------------------------------------------------------------------------------------
    216229
    217         #endregion
     230
     231
     232        #endregion
     233
    218234        #region Event Handling
    219235
  • trunk/CrypPlugins/AutokorrelationFunction/AutokorrelationFunctionSettings.cs

    r1623 r1633  
    2020using Cryptool.PluginBase;
    2121using System.ComponentModel;
     22
     23//------------------------------------------------There is nothing unusual in here------------------------------------------------------------//
    2224
    2325namespace Cryptool.Plugins.AutokorrelationFunction
Note: See TracChangeset for help on using the changeset viewer.