コード例 #1
0
ファイル: ModMatrix.cs プロジェクト: JarLob/CrypTool2
        public ModMatrix(ModMatrix mat)
        {
            Dimension = mat.Dimension;
            Modulus   = mat.Modulus;
            m         = new BigInteger[Dimension, Dimension];

            for (int y = 0; y < Dimension; y++)
            {
                for (int x = 0; x < Dimension; x++)
                {
                    m[x, y] = mat[x, y];
                }
            }
        }
コード例 #2
0
ファイル: ModMatrix.cs プロジェクト: JarLob/CrypTool2
        public ModMatrix invert()
        {
            ModMatrix mi = new ModMatrix(Dimension, Modulus);

            BigInteger di = BigIntegerHelper.ModInverse(det(), Modulus);

            for (int y = 0; y < Dimension; y++)
            {
                for (int x = 0; x < Dimension; x++)
                {
                    int sign = 1 - 2 * ((x + y) % 2);       // sign = (-1) ^ (x+y)
                    mi[x, y] = (((sign * di * minor(y, x)) % Modulus) + Modulus) % Modulus;
                }
            }

            return(mi);
        }
コード例 #3
0
ファイル: ModMatrix.cs プロジェクト: JarLob/CrypTool2
        public static ModMatrix operator *(ModMatrix matA, ModMatrix matB)
        {
            ModMatrix result = new ModMatrix(matA.Dimension, matA.Modulus);

            for (int y = 0; y < result.Dimension; y++)
            {
                for (int x = 0; x < result.Dimension; x++)
                {
                    result[x, y] = 0;
                    for (int i = 0; i < result.Dimension; i++)
                    {
                        result[x, y] += matA[i, y] * matB[x, i];
                        result[x, y]  = ((result[x, y] % result.Modulus) + result.Modulus) % result.Modulus;
                    }
                }
            }

            return(result);
        }
コード例 #4
0
ファイル: ModMatrix.cs プロジェクト: JarLob/CrypTool2
        public ModMatrix submatrix(int x, int y)
        {
            ModMatrix submatrix = new ModMatrix(Dimension - 1, Modulus);

            for (int xx = 0, xi = 0; xx < Dimension; xx++)
            {
                if (xx == x)
                {
                    continue;
                }
                for (int yy = 0, yi = 0; yy < Dimension; yy++)
                {
                    if (yy == y)
                    {
                        continue;
                    }
                    submatrix[xi, yi] = m[xx, yy];
                    yi++;
                }
                xi++;
            }

            return(submatrix);
        }