Пример #1
0
        public static void Task5()
        {
            var text = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";

            //var text = "ciphertext";
            //68
            Console.WriteLine((Xor.RepeatingKey(text, "88")));
            var str     = new StringBuilder();
            var results = new Dictionary <int, double>();

            for (var i = 1; i < text.Length / 2; i++)
            {
                str.Append(new string(text.Skip(text.Length - i).ToArray()));
                str.Append(new string(text.Take(text.Length - i).ToArray()));
                var count = text.Select((t1, t) => t1 == str.ToString()[t] ? 1 : 0).Sum();

                var value = (double)count / text.Length;
                str.Clear();
                results.Add(i, value);
                Console.WriteLine("{0} {1}", i, Math.Round(value, 3, MidpointRounding.ToEven));
            }
            var temp = results.ToList();

            temp.Sort((x, m) => x.Value.CompareTo(m.Value));
            temp.Reverse();
            var blocks = new List <string>();

            for (var i = 0; i < 2; i++)
            {
                var distance = temp[i].Key;
                var index    = 0;
                var stringB  = new StringBuilder();

                for (var m = 0; m < distance; m++)
                {
                    index = m;

                    while (index < text.Length)
                    {
                        stringB.Append(text[index]);
                        index += distance;
                    }
                    blocks.Add(stringB.ToString());
                    stringB.Clear();
                }
                //получаем блоки
                var b = Xor.RepeatingKey(blocks[0], " ");
                Console.WriteLine();
            }
        }
Пример #2
0
        private static void Task7()
        {
            string[] text =
            {
                "Burning 'em, if you ain't quick and nimble",
                "I go crazy when I hear a cymbal"
            };
            var key         = "ICE";
            var adaptiveKey = new StringBuilder();

            adaptiveKey.Append(key);

            foreach (var str in text)
            {
                var tmp = Xor.RepeatingKey(str, key);
                Console.WriteLine(tmp);
            }
        }