Exemplo n.º 1
0
        private static char[] ReverceReplaceMap(IReadOnlyList <char> replace_map)
        {
            var reverce = new char[replace_map.Count];

            for (var i = 0; i < replace_map.Count; i++)
            {
                var c = replace_map[i];
                reverce[AbcRus.ToIndex(c)] = AbcRus.FromIndex(i);
            }

            return(reverce.ToArray());
        }
Exemplo n.º 2
0
        public static string FrequencyDecode(string input, string key)
        {
            var fileText = File.ReadAllText("VoinaIMir.txt");

            var table_target = BuildFrequencyTable(fileText);
            var table_source = BuildFrequencyTable(input);

            var replace_map = new char[AbcRus.Size];

            for (var i = 0; i < replace_map.Length; i++)
            {
                var index = table_target.FindIndex(x => x.Item1 == i);

                replace_map[i] = AbcRus.FromIndex(table_source[index].Item1);
            }

            return(ReplaceString(input, replace_map));
        }
Exemplo n.º 3
0
        private static string ReplaceString(string input, IReadOnlyList <char> replace_map)
        {
            var result = "";

            foreach (var c in input)
            {
                if (AbcRus.IsValid(c))
                {
                    result = result + replace_map[AbcRus.ToIndex(c)];
                }
                else
                {
                    result = result + c;
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        private static List <Tuple <int, long> > BuildFrequencyTable(string Text)
        {
            var table = new Dictionary <int, long>();

            for (var i = 0; i < AbcRus.Size; i++)
            {
                table.Add(i, 0);
            }

            foreach (var c in Text)
            {
                if (AbcRus.IsValid(c))
                {
                    table[AbcRus.ToIndex(c)]++;
                }
            }

            return(table.Select(x => Tuple.Create(x.Key, x.Value)).OrderBy(x => x.Item2).ToList());
        }