当前位置: 首页>>代码示例>>C#>>正文


C# State.GetColumn方法代码示例

本文整理汇总了C#中State.GetColumn方法的典型用法代码示例。如果您正苦于以下问题:C# State.GetColumn方法的具体用法?C# State.GetColumn怎么用?C# State.GetColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在State的用法示例。


在下文中一共展示了State.GetColumn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InverseLayer

        protected override void InverseLayer(State state)
        {
            byte[] tempVector = new byte[4];

            for (int col = 0; col < state.Columns; col++)
            {
                ByteMatrixColumn currentColumn = state.GetColumn(col);

                // Multiply each column by d(x) which is the inverse of c(x). This means:
                // c(x) * d(x) ≡ 1, which expanded is
                // (03*x^3 ⊕ 01*x^2 ⊕ 01*x ⊕ 02) * d(x) ≡ 1

                // After some derivation, we can calculate that 
                // d(x) = 0B*x^3 ⊕ 0D*x^2 ⊕ 09*x ⊕ 0E;

                // This is the same as multiplication by this matrix:
                // | 0E 0B 0D 09 |   | x0 |
                // | 09 0E 0B 0D |   | x1 |
                // | 0D 09 0E 0B | * | x2 |
                // | 0B 0D 09 0E |   | x3 |

                // We can perform this multiply by starting with the top row of the matrix:
                // [0E 0B 0D 09] and keep rotating it by 1 each column. Note that the multiply
                // is in the Rijndael field.

                for (int row = 0; row < 4; row++)
                {
                    tempVector[row] = (byte) (
                                                 FiniteFieldMath.Multiply(0x0E, currentColumn[row]) ^
                                                 FiniteFieldMath.Multiply(0x0B, currentColumn[(row + 1)%4]) ^
                                                 FiniteFieldMath.Multiply(0x0D, currentColumn[(row + 2)%4]) ^
                                                 FiniteFieldMath.Multiply(0x09, currentColumn[(row + 3)%4]));
                }

                // Now that we have the result of the multiply in tempVector, we 
                // copy it back to the state matrix:
                for (int row = 0; row < 4; row++)
                {
                    currentColumn[row] = tempVector[row];
                }
            }
        }
开发者ID:hartsock,项目名称:AES-Illustrated,代码行数:42,代码来源:MixColumns.cs

示例2: ApplyLayer

        protected override void ApplyLayer(State state)
        {
            byte[] tempVector = new byte[4];

            for (int col = 0; col < state.Columns; col++)
            {
                ByteMatrixColumn currentColumn = state.GetColumn(col);

                // Multiply each column by c(x) which is defined as 
                // c(x) = 03*x^3 ⊕ 01*x^2 ⊕ 01*x ⊕ 02;

                // This is the same as multiplication by this matrix:
                // | 02 03 01 01 |   | x0 |
                // | 01 02 03 01 |   | x1 |
                // | 01 01 02 03 | * | x2 |
                // | 03 01 01 02 |   | x3 |

                // We can perform this multiply by starting with the top row of the matrix:
                // [02 03 01 01] and keep rotating it by 1 each column. Note that the multiply
                // is in the Rijndael field.
                for (int row = 0; row < 4; row++)
                {
                    tempVector[row] = (byte) (
                                                 FiniteFieldMath.Multiply(0x02, currentColumn[row]) ^
                                                 FiniteFieldMath.Multiply(0x03, currentColumn[(row + 1)%4]) ^
                                                 FiniteFieldMath.Multiply(0x01, currentColumn[(row + 2)%4]) ^
                                                 FiniteFieldMath.Multiply(0x01, currentColumn[(row + 3)%4]));
                }

                // Now that we have the result of the multiply in tempVector, we 
                // copy it back to the state matrix:
                for (int row = 0; row < 4; row++)
                {
                    currentColumn[row] = tempVector[row];
                }
            }
        }
开发者ID:hartsock,项目名称:AES-Illustrated,代码行数:37,代码来源:MixColumns.cs


注:本文中的State.GetColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。