Ignore:
Timestamp:
Dec 2, 2008, 3:23:10 PM (13 years ago)
Author:
Danail Vazov
Message:

Modifications to input made. Input is now "bound" with the FrequencyTest input of the same type.

File:
1 edited

Legend:

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

    r98 r99  
    66using Cryptool.PluginBase.Analysis;
    77using System.ComponentModel;
     8using System.Collections;
    89
    910namespace FriedmanTest
     
    2223        }
    2324    #region Private Variables
    24     private int integerValue;
    25     private string stringInput="";
     25    private double keyLength;
    2626    private string stringOutput="";
     27    private int [] arrayInput;
    2728    #endregion
    2829
     
    3031    #region Properties (Inputs/Outputs)
    3132
    32     [PropertyInfo(Direction.Input, "The string to be analyzed", "Caution: Aplaying a string, other than the one outputed from the FrequencyTest plug-in, will result in ilogical results", "",false, true, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    33     public string StringInput
     33    [PropertyInfo(Direction.Output,"Probable key length.", "For greater accuracy, please refer to the string output.", "",false , false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     34    public double KeyLength
    3435    {
    35         get
    36         {
    37             return stringInput;
    38         }
    39         set { stringInput = value; OnPropertyChanged("StringInput"); }
    40     }
    41     [PropertyInfo(Direction.Output,"Probable key length.", "For greater accuracy, please refer to the string output.", "",false , false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    42     public int IntegerValue
    43     {
    44         get { return integerValue; }
     36        get { return keyLength; }
    4537        set
    4638        {
    47             if (value != integerValue)
     39            if (value != keyLength)
    4840            {
    49                 integerValue = value;
    50                 OnPropertyChanged("IntegerValue");
     41                keyLength = value;
     42                OnPropertyChanged("KeyLength");
    5143            }
    5244        }
     
    6355        }
    6456    }
     57    [PropertyInfo(Direction.Input, "List input", "absolute frequency of the letter, as calculated by FrequencyTest", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     58    public int [] ArrayInput
     59    {
     60        get { return arrayInput; }
     61        set
     62        {
     63            arrayInput = value;
     64            OnPropertyChanged("ArrayInput");
     65
     66        }
     67    }
    6568    #endregion
    6669
     
    99102        {
    100103           
    101             if (stringInput != null)
     104            if (arrayInput != null)
    102105            {
    103106                double Kp; //Kappa "plain-text"
     
    112115                    default: Kp = 0.0667; break;
    113116                }
    114                 //Edit the input from Frequency Test in order to extract the observed letter frequencies
    115                 string string1 = stringInput;
    116                 string string2 = string1.Replace(Environment.NewLine, ":");
    117                
    118                
    119                 string[] split = null;
    120 
    121 
    122 
    123117               
    124                 split = string2.Split(':');
    125118               
    126119                //Now we put the needed absolute values of the letter frequencies into an array
    127                 int[] absolutevalue = new int[Convert.ToInt32(split.Length / 3)];
    128                
    129                 int j = 0;
    130                 for (int i = 1; i <= split.Length-2; i=i+3)
    131                 {
    132                 absolutevalue[j] = Convert.ToInt32(split[i]);
    133                 j++;
    134 
    135                 }
    136                
     120                int[] absolutevalue = new int[arrayInput.Length];
     121                for (int i = 0; i <= arrayInput.Length-1;i++ )
     122                {
     123                    absolutevalue[i] = arrayInput[i];
     124                }
    137125                //Now we begin calculation of the arithmetic sum of the frequencies
    138126                int[] summ=new int [absolutevalue.Length];
     
    148136                     
    149137                }
    150                 //outputString = Convert.ToString(summ1);
    151                 //OnPropertyChanged("OutputString");
    152 
    153138                //Now we calculate the length of text from the observed letter frequencies
    154139                int texLen = 0;
     
    157142                    texLen += y;
    158143                }
    159                 //outputString = Convert.ToString(texLen);
    160                 //OnPropertyChanged("OutputString");
    161144                double normTexLen = texLen * (texLen - 1); //Normalize the text length in order to calculate the observed index of coincidence
    162                 //outputString = Convert.ToString(Convert.ToDecimal(normTexLen));
    163                 //OnPropertyChanged("OutputString");
    164145                double obIC = summ1/normTexLen; //Calculates the observed index of coincidence
    165                 //outputString = Convert.ToString(Convert.ToDecimal(obIC));
    166                 //OnPropertyChanged("OutputString");
    167                 double Kr = 0.038; //Kappa "random" - expected coincidence rate for a uniform distribution of the alphabet. In this case 1/26, hence we should have a 26 letter alphabet on the input.
    168                  
     146                double Kr = 0.038; //Kappa "random" - expected coincidence rate for a uniform distribution of the alphabet. In this case 1/26, hence we should have a 26 letter alphabet on the input.   
    169147                double keyLen = 0.027 * texLen / (((texLen - 1) * obIC) - (Kr * texLen) + Kp);
    170148                stringOutput = Convert.ToString(keyLen);
     149                keyLength = keyLen;
    171150                OnPropertyChanged("OutputString");
     151                OnPropertyChanged("KeyLength");
    172152                if (OnPluginProgressChanged != null)
    173153                {
Note: See TracChangeset for help on using the changeset viewer.