Пример #1
0
        public byte[] ProcessBlockInBytes(byte[] block, bool isFirstBlock = false)
        {
            var roundModels = RoundService.GetRoundModels(block);

            if (isFirstBlock)
            {
                MDBuffer.ResetBuffer();
            }

            foreach (var roundModel in roundModels)
            {
                var startupBuffer = MDBuffer.Clone();

                for (int cycleNumber = 0; cycleNumber < CycleCount; cycleNumber++)
                {
                    for (int i = 0; i < RoundStepsCount; i++)
                    {
                        var a = MDBuffer[0, i % 4];
                        var b = MDBuffer[1, i % 4];
                        var c = MDBuffer[2, i % 4];
                        var d = MDBuffer[3, i % 4];

                        var idx = RoundService.GetRoundIdx(i, cycleNumber);

                        RoundService.ApplyRoundFunction(
                            ref a, b, c, d,
                            roundModel[idx],
                            (i + 1) + 16 * cycleNumber,
                            RoundService.S[cycleNumber, i % 4],
                            cycleNumber);

                        MDBuffer[i % 4] = a;
                    }
                }

                MDBuffer = MDBuffer + startupBuffer;
            }

            var result = new byte[16];

            Array.Copy(BitConverter.GetBytes(MDBuffer.A), 0, result, 0, 4);
            Array.Copy(BitConverter.GetBytes(MDBuffer.B), 0, result, 4, 4);
            Array.Copy(BitConverter.GetBytes(MDBuffer.C), 0, result, 8, 4);
            Array.Copy(BitConverter.GetBytes(MDBuffer.D), 0, result, 12, 4);

            return(result);
        }
Пример #2
0
        public string ProcessBlock(byte[] block, bool isFirstBlock = false)
        {
            var roundModels = RoundService.GetRoundModels(block);

            if (isFirstBlock)
            {
                MDBuffer.ResetBuffer();
            }

            foreach (var roundModel in roundModels)
            {
                var startupBuffer = MDBuffer.Clone();

                for (int cycleNumber = 0; cycleNumber < CycleCount; cycleNumber++)
                {
                    for (int i = 0; i < RoundStepsCount; i++)
                    {
                        var a = MDBuffer[0, i % 4];
                        var b = MDBuffer[1, i % 4];
                        var c = MDBuffer[2, i % 4];
                        var d = MDBuffer[3, i % 4];

                        var idx = RoundService.GetRoundIdx(i, cycleNumber);

                        RoundService.ApplyRoundFunction(
                            ref a, b, c, d,
                            roundModel[idx],
                            (i + 1) + 16 * cycleNumber,
                            RoundService.S[cycleNumber, i % 4],
                            cycleNumber);

                        MDBuffer[i % 4] = a;
                    }
                }

                MDBuffer = MDBuffer + startupBuffer;
            }

            return(MDBuffer.ToString());
        }