Ejemplo n.º 1
0
        public static string Encode(string word, int n)
        {
            List <char>[] lists = new List <char> [n];
            for (int i = 0; i < n; i++)
            {
                lists[i] = new List <char>();
            }
            List <int> IndexesLists = ListGenerator.Generate(n);
            string     stringout    = "";
            int        point        = 0;

            for (int i = 0; i < word.Length; i++)
            {
                lists[IndexesLists[point]].Add(word[i]);
                ListGenerator.NextIndex(IndexesLists, ref point);
            }
            for (int i = 0; i < lists.Length; i++)
            {
                stringout += ListGenerator.GetStringFromList(lists[i]);
            }
            return(stringout);
        }
Ejemplo n.º 2
0
        public static string Decode(string word, int n)
        {
            List <char>[] lists = new List <char> [n];
            for (int i = 0; i < n; i++)
            {
                lists[i] = new List <char>();
            }
            List <int> IndexesLists = ListGenerator.Generate(n);
            int        point        = 0;

            for (int i = 0; i < word.Length; i++)
            {
                lists[IndexesLists[point]].Add(word[i]);

                ListGenerator.NextIndex(IndexesLists, ref point);
            }
            int wordindex = 0;

            for (int i = 0; i < lists.Length; i++)
            {
                for (int j = 0; j < lists[i].Count; j++)
                {
                    lists[i][j] = word[wordindex];
                    wordindex++;
                }
            }
            string stringout = "";

            point = 0;
            for (int i = 0; i < word.Length; i++)
            {
                stringout += lists[IndexesLists[point]][0];
                lists[IndexesLists[point]].RemoveAt(0);
                ListGenerator.NextIndex(IndexesLists, ref point);
            }
            return(stringout);
        }