Example #1
0
File: GOST.cs Project: Kant8/ISM
        private UInt32 Substitution(UInt32 block)
        {
            UInt32 result = 0;

            const int subBlockSize = 4;
            const int subBlocksCount = 8;
            for (var subBlockIndex = 0; subBlockIndex < subBlocksCount; subBlockIndex++)
            {
                Byte subBlock = 0;
                for (int i = 0; i < subBlockSize; i++)
                {
                    var bit = block.GetBit(subBlockIndex * subBlockSize + i);
                    BitHelper.SetBit(ref subBlock, i, bit);
                }

                var sRes = SBlocks[subBlocksCount - subBlockIndex - 1][subBlock];

                for (int i = 0; i < subBlockSize; i++)
                {
                    var bit = sRes.GetBit(i);
                    BitHelper.SetBit(ref result, subBlockIndex * subBlockSize + i, bit);
                }
            }
            return result;
        }