Esempio n. 1
0
 public static UInt64 PermutateBlock(UInt64 block, byte[] table,
     bool startFrom0 = true)
 {
     UInt64 resultBlock = 0;
     for (int i = 0; i < table.Length; i++)
     {
         var bit = block.GetBit(startFrom0 ? table[i] : table[i] - 1);
         BitHelper.SetBit(ref resultBlock, i, bit);
     }
     return resultBlock;
 }
Esempio n. 2
0
File: DES.cs Progetto: Kant8/ISM
        private UInt32 Substitution(UInt64 block)
        {
            UInt32 result = 0;

            const int subBlockResultSize = 4;
            const int subBlockSize = 6;
            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);
                }

                byte sRowIndex = 0;
                BitHelper.SetBit(ref sRowIndex, 0, subBlock.GetBit(0));
                BitHelper.SetBit(ref sRowIndex, 1, subBlock.GetBit(5));

                byte sColIndex = 0;
                for (int i = 0; i < subBlockResultSize; i++)
                {
                    BitHelper.SetBit(ref sColIndex, i, subBlock.GetBit(i+1));
                }

                var sRes = SBlocks[subBlocksCount - subBlockIndex - 1][sRowIndex, sColIndex];

                for (int i = 0; i < subBlockResultSize; i++)
                {
                    var bit = sRes.GetBit(i);
                    BitHelper.SetBit(ref result, subBlockIndex * subBlockResultSize + i, bit);
                }
            }
            return result;
        }
Esempio n. 3
0
File: DES.cs Progetto: Kant8/ISM
 private UInt64 InitialPermutation(UInt64 block)
 {
     UInt64 resultBlock = 0;
     for (int i = 0; i < IpTable.Length; i++)
     {
         var bit = block.GetBit(IpTable[i] - 1);
         BitHelper.SetBit(ref resultBlock, i, bit);
     }
     return resultBlock;
 }