Ejemplo n.º 1
0
            public static DigraphTable Random(int year, int month)
            {
                DigraphTable result = new DigraphTable();

                for (int y = 0; y < Constants.ALPHABET.Length; y++)
                {
                    for (int x = 0; x < Constants.ALPHABET.Length; x++)
                    {
                        Digraph newDigraph = new Digraph
                        {
                            PlainTextX = Constants.ALPHABET[x],
                            PlainTextY = Constants.ALPHABET[y]
                        };

                        result.cell_list.Add(newDigraph);
                        result.cells[x, y] = newDigraph;
                    }
                }

                List <Tuple <Digraph, double> > values = new List <Tuple <Digraph, double> >();

                foreach (var item in result.cell_list)
                {
                    values.Add(new Tuple <Digraph, double>(item, RandomUtil._rand.NextDouble()));
                }
                values.Sort((v1, v2) => v1.Item2.CompareTo(v2.Item2));

                while (values.Any())
                {
                    var f = values.First();
                    var l = values.Last();

                    f.Item1.CipherTextX = l.Item1.PlainTextX;
                    f.Item1.CipherTextY = l.Item1.PlainTextY;

                    l.Item1.CipherTextX = f.Item1.PlainTextX;
                    l.Item1.CipherTextY = f.Item1.PlainTextY;

                    values.Remove(f);
                    values.Remove(l);
                }

                return(result);
            }
Ejemplo n.º 2
0
 public static string GenerateDigraphTable(int year, int month)
 {
     return(DigraphTable.Random(year, month).ToString());
 }