private void TransformText(byte[] text, IBlockCipherEngine engine, int numberOfBlocks, int originalPayloadBitLength)
        {
            // When the payload meets the block size, do nothing
            if (numberOfBlocks == 1 || originalPayloadBitLength % engine.BlockSizeBits == 0)
            {
                return;
            }

            // When the text does not match a mod of the block size, swap the final two blocks
            for (int i = 0; i < engine.BlockSizeBytes; i++)
            {
                var secondToLastBlockIndex = (numberOfBlocks - 2) * engine.BlockSizeBytes + i;
                var lastBlockIndex         = (numberOfBlocks - 1) * engine.BlockSizeBytes + i;

                SwapBytesHelper.SwapBytes(text, secondToLastBlockIndex, lastBlockIndex);
            }
        }
示例#2
0
        private void TransformText(byte[] text, IBlockCipherEngine engine, int numberOfBlocks, int originalPayloadBitLength)
        {
            // No blocks to swap when there's only a single block to work with
            if (numberOfBlocks == 1)
            {
                return;
            }

            // Swap the final two blocks
            for (int i = 0; i < engine.BlockSizeBytes; i++)
            {
                var secondToLastBlockIndex = (numberOfBlocks - 2) * engine.BlockSizeBytes + i;
                var lastBlockIndex         = (numberOfBlocks - 1) * engine.BlockSizeBytes + i;

                SwapBytesHelper.SwapBytes(text, secondToLastBlockIndex, lastBlockIndex);
            }
        }