Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 };
- private int GetKeyLength(string sCipherText)
- {
- int iSize = 30;
- double[] colCoincidence = new double[iSize + 1];
- int iTextLength = sCipherText.Length;
- for (int i = 0; i <= iSize; i++)
- {
- int iDiv = iTextLength - i;
- for (int j = 0; j < sCipherText.Length; j++)
- {
- if (i + j >= sCipherText.Length)
- break;
- char c = sCipherText[j];
- char k = sCipherText[i + j];
- if(c == k)
- colCoincidence[i] = colCoincidence[i] + 1;
- }
- colCoincidence[i] /= iDiv;
- }
- List<int> colIndexes = new List<int>();
- double dMinValue = 0.06;
- //double dEnglishValue = 0.067;
- double dMaxValue = 0.075;
- for (int i = 1; i < colCoincidence.Length; i++)
- {
- double dValue = colCoincidence[i];
- if ((dValue >= dMinValue && dValue <= dMaxValue) || dValue == 1.0)
- colIndexes.Add(i);
- }
- int iIndex = -1;
- if (colIndexes.Count > 0)
- iIndex = colIndexes[0];
- return iIndex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement