Exemple #1
0
        static public void TestMethod()
        {
            var matrix = (Matrix)Matrix.Build.Dense(8, 8);

            for (var i = 0; i < 8; i++)
            {
                for (var j = 0; j < 8; j++)
                {
                    matrix.At(i, j, i * 8 + j);
                }
            }
            var orderArray = new int[3] {
                2, 0, 1
            };

            matrix = ClassicalAlgorithm.PermuteSys(matrix, orderArray);
            Console.WriteLine(matrix);
        }
Exemple #2
0
        public Task OnSession(string algName)
        {
            //set up the alg
            _alg = algName switch
            {
                "playfair" => new Playfair(),
                "caesar" => new Caesar(),
                "vigenere" => new Vigenere(),
                _ => throw
                    new InvalidOperationException("The classical algorithm provided is unknown")
            };

            _alg.Alphabet = algName == "playfair" ? Alphabets.ASCIIPerfect :
                            Alphabets.ASCII;

            while (true)
            {
                var resp = Ask(null, false, true);

                if (resp.ToLower() == "back")
                {
                    return(Task.CompletedTask);
                }

                bool valid = false;
                foreach (var gen in GenCommands)
                {
                    var args = resp.Remove(0, gen.Length + 1);
                    if (resp.ToLower().StartsWith($"{gen} "))
                    {
                        OnGenCommand(gen, args);
                        valid = true;
                        break;
                    }
                }
                if (!valid)
                {
                    Speak("Not a valid command");
                }
            }
        }
    }
        static public void TestMethod()
        {
            var matrixArray0 = new List <Matrix>();

            Complex[,] array0 = { { new Complex(0,            1),  1 },
                                  {             1, new Complex(0, 1) } };
            matrixArray0.Add((Matrix)Matrix.Build.DenseOfArray(array0));


            var matrixArray1 = new List <Matrix>();

            Complex[,] array1 = { {             1, new Complex(0, 1) },
                                  { new Complex(0,            1),  1 } };
            matrixArray1.Add((Matrix)Matrix.Build.DenseOfArray(array0));
            matrixArray1.Add((Matrix)Matrix.Build.DenseOfArray(array1));

            var ret0 = ClassicalAlgorithm.RepresentationGenerater(matrixArray0);
            var ret1 = ClassicalAlgorithm.RepresentationGenerater(matrixArray1);

            Console.WriteLine("ret0");
            Console.WriteLine(ret0.ToComplexString());
            Console.WriteLine("ret1");
            Console.WriteLine(ret1.ToComplexString());
        }