Advertisement
Guest User

Untitled

a guest
May 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private double[] m_cHISTOGRAM = new double[] { .082, .015, .028, .043, .127, .022, .020, .061, .070, .002, .008, .040, .024, .067, .075, .019, .001, .060, .063, .091, .028, .010, .023, .001, .020, .001 };
  2.  
  3. private int GetKeyLength(string sCipherText)
  4.        {
  5.            int iSize = 30;
  6.            double[] colCoincidence = new double[iSize + 1];
  7.            int iTextLength = sCipherText.Length;
  8.            
  9.            for (int i = 0; i <= iSize; i++)
  10.            {
  11.                int iDiv = iTextLength - i;
  12.  
  13.                for (int j = 0; j < sCipherText.Length; j++)
  14.                {
  15.                    if (i + j >= sCipherText.Length)
  16.                        break;
  17.  
  18.                    char c = sCipherText[j];
  19.                    char k = sCipherText[i + j];
  20.  
  21.                    if(c == k)
  22.                        colCoincidence[i] = colCoincidence[i] + 1;
  23.                }
  24.  
  25.                colCoincidence[i] /= iDiv;
  26.            }
  27.  
  28.            List<int> colIndexes = new List<int>();
  29.            double dMinValue = 0.06;
  30.            //double dEnglishValue = 0.067;
  31.            double dMaxValue = 0.075;
  32.  
  33.            for (int i = 1; i < colCoincidence.Length; i++)
  34.            {
  35.                double dValue = colCoincidence[i];
  36.  
  37.                if ((dValue >= dMinValue && dValue <= dMaxValue) || dValue == 1.0)
  38.                    colIndexes.Add(i);
  39.            }
  40.            
  41.            int iIndex = -1;
  42.  
  43.            if (colIndexes.Count > 0)
  44.                iIndex = colIndexes[0];
  45.  
  46.            return iIndex;
  47.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement