Example #1
0
        public static bool[] ToBooleans(this UInt32 value)
        {
            var rlt = new bool[sizeof(UInt32)];

            for (int i = 0; i < rlt.Length; i++)
            {
                rlt[i] = value.GetBit(i);
            }
            return(rlt);
        }
Example #2
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;
        }
 public static int CountBits(this Bitset value) =>
 Enumerable.Range(0, 32).Count(index => value.GetBit(index));