Changeset 450


Ignore:
Timestamp:
Sep 1, 2009, 6:04:49 PM (12 years ago)
Author:
Danail Vazov
Message:

Added option for maximum keylength to analyse. Changed some statistical data, to slightly enhance precision of analysis procedure.

Location:
trunk/CrypPlugins/VigenereAnalyser
Files:
2 edited

Legend:

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

    r426 r450  
    2626        public string cipherText;
    2727        public double sequenceIC;
    28         public int RC_keyLength;
     28        public int IC_keyLength;
    2929        public int shiftKey = 0;
    3030        private double[] elf;
     31        private double eic;
    3132        private VAPresentation vaPresentation;
    3233        private char[] validchars = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; //Sets alphabet of valid characters
     
    117118            return new List<int>();
    118119        }
    119         private int chiSquare(string text)
     120        private int leastSquares(string text)
    120121        {   
    121122            text=text.Replace(Environment.NewLine, ":");
     
    184185                {
    185186                    int n = (y + j)%26;
    186                     /*if (n > 25)
    187                     {
    188                         n = n - 25;
    189                     }*/
    190187                    chi = expectedFrequencies[j]-observedFrequencies[n];
    191188                    chiS = (Math.Pow(chi, 2));
     
    247244            for (int k = 0; k < d; k++)
    248245            {
    249                sum1 += Math.Pow((IC[k] - 0.066), 2);
     246               sum1 += Math.Pow((IC[k] - eic), 2);
    250247            }
    251248            return sequenceIC = Math.Sqrt((sum1 / d));
     
    253250           
    254251        }
    255         private int RCtest()
    256         {
    257             int max_keyLength = 30;
     252        private int sieveIC()
     253        {
     254            int max_keyLength = settings.Max_Keylength;
     255            if (cipherText.Length < max_keyLength)
     256            {
     257                ShowStatusBarMessage("The maximum keylength to be analysed is bigger than the length of the ciphertext. Adjusting maximum keylength to be equal to the ciphertext length, in order to avoid errors.", NotificationLevel.Info);
     258                max_keyLength = cipherText.Length - 1;
     259            }
    258260            double check;
    259261            double max_diff = 0.002;
    260             RC_keyLength = 1;
     262            IC_keyLength = 1;
    261263            double min_keyLength=seqIC(1);
    262264            for (int i = 2; i <max_keyLength; i++)
     
    265267                 if (min_keyLength-check>max_diff)
    266268                 {
    267                      RC_keyLength = i;
     269                     IC_keyLength = i;
    268270                     min_keyLength = check;
    269271                 }
    270272            }
    271             return RC_keyLength;
     273            return IC_keyLength;
    272274        }
    273275        #endregion
     
    435437           {
    436438                //take care of settings first...
    437                 switch (settings.ELF)
    438                 {
    439                    case 1: elf = new double[26] { 8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074 }; break;
    440                    case 2: elf = new double[26] { 8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074 }; break;
     439               switch (settings.EIC)
     440               {
     441                   case 1: eic=0.0766; break;
     442                   case 2: eic = 0.0746; break;
     443                   case 3: eic=0.0775; break;
     444                   case 4: eic =0.0775; break;
     445                   case 5: eic = 0.074528; break;
     446                   default: eic = 0.0665; break;
     447               }
     448               switch (settings.ELF)
     449               {
     450                   case 1: elf = new double[26] { 6.51, 1.89, 3.06, 5.08, 17.4, 1.66, 3.01, 4.76, 7.55, 0.27, 1.21, 3.44, 2.53, 9.78, 2.51, 0.79, 0.02, 7, 7.27, 6.15, 4.35, 0.67, 1.89, 0.03, 0.04, 1.13 }; break;
     451                   case 2: elf = new double[26] { 7.636, 0.901, 3.26, 3.669, 14.715, 1.066, 0.866, 0.737, 7.529, 0.545, 0.049, 5.456, 2.968, 7.095, 5.378, 3.021, 1.362, 6.553, 7.948, 7.244, 6.311, 1.628, 0.114, 0.387, 0.308, 0.136 }; break;
    441452                   case 3: elf = new double[26] { 8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074 }; break;
    442453                   case 4: elf = new double[26] { 8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074 }; break;
    443454                   case 5: elf = new double[26] { 8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074 }; break;
    444455                   default: elf = new double[26] { 8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074 }; break;
    445                 }
     456               }
    446457               
    447458                if (vigToCaes==null)
     
    467478                    if (settings.internalKeyLengthAnalysis == 1)
    468479                    {
    469                         RCtest();
    470                         probableKeylength = RC_keyLength;
     480                        sieveIC();
     481                        probableKeylength = IC_keyLength;
    471482
    472483                    }
     
    482493                        int[][] proposedKeylengths =
    483494                {
    484                  new int[] {0,0,0,0,0,0,0,0,0,0,0},
    485                  new int[] {0,0,0,0,0,0,0,0,0,0,0}
     495                 new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0},
     496                 new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0}
    486497   
    487498                };
     
    666677                            if (c != null)
    667678                            {
    668                                 chiSquare(c);
     679                                leastSquares(c);
    669680                                chiList.Add(shiftKey);
    670681                            }
  • trunk/CrypPlugins/VigenereAnalyser/VigenereAnalyserSettings.cs

    r426 r450  
    1313    {
    1414        #region ISettings Members
     15        private int max_keylength=15;
    1516        private int elf = 0;
     17        private int eic = 0;
    1618        public int internalKeyLengthAnalysis = 0;
    1719        public int columnAnalysis = 0;
     
    2931            }
    3032        }
    31         [ContextMenu("Method of keylength analysis", "Select the internal or external method for analysis of the keylength", 2, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, new String[] { "Use Kasiski and Friedman tests (external)","Use Regression-Covariance test (internal)" })]
    32         [TaskPane("Method of keylength analysis", "Select the internal or external method for analysis of the keylength", null, 2, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "Use Kasiski and Friedman tests (external)", "Use Regression-Covariance test (internal)" })]
     33        [ContextMenu("Expected Index of coincidence", "Adjust the expected index of coincidence", 2, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, new String[] { "English", "German", "French", "Spanish", "Italian", "Portugeese" })]
     34        [TaskPane("Expected Index of coincidence", "Adjust the expected index of coincidence", null, 2, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "English", "German", "French", "Spanish", "Italian", "Portugeese" })]
     35        public int EIC // Expected Letter Frequencies
     36        {
     37            get { return this.eic; }
     38            set
     39            {
     40                if (((int)value) != eic) hasChanges = true;
     41                this.eic = (int)value;
     42                OnPropertyChanged("EIC");
     43            }
     44        }
     45
     46        [TaskPane("Maximum Keylength", "Enter maximum keylength to be analysed by the 'Sampled Index of coincidence' method. default = 15", "", 1, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, 100)]
     47        public int Max_Keylength
     48        {
     49            get { return this.max_keylength; }
     50            set
     51            {
     52                if (value != max_keylength)
     53                {
     54                    HasChanges = true;
     55                    max_keylength = value;
     56                }
     57            }
     58        }
     59        [ContextMenu("Method of keylength analysis", "Select the internal or external method for analysis of the keylength", 2, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, new String[] { "Kasiski and Friedman tests (external)","Sampled index of coincidence(internal)" })]
     60        [TaskPane("Method of keylength analysis", "Select the internal or external method for analysis of the keylength", null, 2, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "Kasiski and Friedman tests (external)", "Sampled index of coincidence (internal)" })]
    3361        public int InternalKeyLengthAnalysis
    3462        {
Note: See TracChangeset for help on using the changeset viewer.