Exemplo n.º 1
0
 public DES(string key)
 {
     this.key     = BitManipulator.StringToBinary(key);
     this.allKeys = new bool[16][];
     this.sboxes  = new List <int[, ]>();
     this.sboxes.Add(s1);
     this.sboxes.Add(s2);
     this.sboxes.Add(s3);
     this.sboxes.Add(s4);
     this.sboxes.Add(s5);
     this.sboxes.Add(s6);
     this.sboxes.Add(s7);
     this.sboxes.Add(s8);
     this.GenerateKeys();
 }
Exemplo n.º 2
0
        private void SetBlocksOfPlainText(string secretMsg)
        {
            bool[] secretMsgBits = BitManipulator.StringToBinary(secretMsg);
            int    numOfBlocks   = secretMsgBits.Length / 64;

            numOfBlocks = (secretMsgBits.Length % 64 != 0) ? ++numOfBlocks : numOfBlocks;
            blocks      = new bool[numOfBlocks][];
            bool[] block = new bool[64];
            int    i, j = 0, count = 0;

            /////Padding & Block Division
            for (i = 0; i < secretMsgBits.Length && j < numOfBlocks; i++)
            {
                if (count == 63)
                {
                    block[count] = secretMsgBits[i];
                    blocks[j]    = block;
                    block        = new bool[64];
                    j++;
                    count = 0;
                }
                else
                {
                    block[count] = secretMsgBits[i];
                    ++count;
                    if (i == secretMsgBits.Length - 1)
                    {
                        blocks[j] = block;
                    }
                }
            }
            if (count != 0)
            {
                for (int k = count; k < 64; k++)
                {
                    blocks[j][k] = false;
                }
            }
        }