コード例 #1
0
        public void FixKey(string post)
        {
            var pre             = VigenereDecrypter.TextOnlyLetters;
            var postOnlyLetters = new string(post.Where(Char.IsLetter).ToArray());
            var ind             = -1;

            for (var i = 0; i < Math.Min(pre.Length, postOnlyLetters.Length); i++)
            {
                if (pre[i] == postOnlyLetters[i])
                {
                    continue;
                }

                ind = i;
                break;
            }

            var k = ind % Mu;

            var keychar = VigenereDecrypter.Decrypt(VigenereDecrypter.Key[k],
                                                    VigenereDecrypter.Decrypt(postOnlyLetters[ind], pre[ind]));

            VigenereDecrypter.Key =
                new string(VigenereDecrypter.Key.Select((c, i) => i == k ? keychar : c).ToArray());
        }
コード例 #2
0
        public void SuggestMostOccuring(int index, char letter)
        {
            var most = Enumerable.Range(0, VigenereDecrypter.CipherTextOnlyLetters.Length / Mu)
                       .Select(i => VigenereDecrypter.CipherTextOnlyLetters.Substring(i * Mu, Mu))
                       .Select(i => i[index])
                       .Aggregate(new Dictionary <char, int>(),
                                  (charcouner, c) =>
            {
                charcouner[c] = charcouner.ContainsKey(c) ? charcouner[c] + 1 : 1;
                return(charcouner);
            })
                       .OrderByDescending(pair => pair.Value)
                       .First()
                       .Key;

            var keychar = VigenereDecrypter.Decrypt(most, letter);

            VigenereDecrypter.Key =
                new string(VigenereDecrypter.Key.Select((c, i) => i == index ? keychar : c).ToArray());
        }