Renci.SshNet.Security.Cryptography.Ciphers.DesCipher.GenerateWorkingKey C# (CSharp) Method

GenerateWorkingKey() protected method

Generates the working key.
protected GenerateWorkingKey ( bool encrypting, byte key ) : int[]
encrypting bool if set to true [encrypting].
key byte The key.
return int[]
        protected int[] GenerateWorkingKey(bool encrypting, byte[] key)
        {
            ValidateKey();

            int[] newKey = new int[32];
            bool[] pc1m = new bool[56];
            bool[] pcr = new bool[56];

            for (int j = 0; j < 56; j++)
            {
                int l = pc1[j];

                pc1m[j] = ((key[(uint)l >> 3] & bytebit[l & 07]) != 0);
            }

            for (int i = 0; i < 16; i++)
            {
                int l, m;

                if (encrypting)
                {
                    m = i << 1;
                }
                else
                {
                    m = (15 - i) << 1;
                }

                var n = m + 1;
                newKey[m] = newKey[n] = 0;

                for (int j = 0; j < 28; j++)
                {
                    l = j + totrot[i];
                    if (l < 28)
                    {
                        pcr[j] = pc1m[l];
                    }
                    else
                    {
                        pcr[j] = pc1m[l - 28];
                    }
                }

                for (int j = 28; j < 56; j++)
                {
                    l = j + totrot[i];
                    if (l < 56)
                    {
                        pcr[j] = pc1m[l];
                    }
                    else
                    {
                        pcr[j] = pc1m[l - 28];
                    }
                }

                for (int j = 0; j < 24; j++)
                {
                    if (pcr[pc2[j]])
                    {
                        newKey[m] |= bigbyte[j];
                    }

                    if (pcr[pc2[j + 24]])
                    {
                        newKey[n] |= bigbyte[j];
                    }
                }
            }

            //
            // store the processed key
            //
            for (int i = 0; i != 32; i += 2)
            {
                var i1 = newKey[i];
                var i2 = newKey[i + 1];

                newKey[i] = (int)((uint)((i1 & 0x00fc0000) << 6) |
                                    (uint)((i1 & 0x00000fc0) << 10) |
                                    ((uint)(i2 & 0x00fc0000) >> 10) |
                                    ((uint)(i2 & 0x00000fc0) >> 6));

                newKey[i + 1] = (int)((uint)((i1 & 0x0003f000) << 12) |
                                      (uint)((i1 & 0x0000003f) << 16) |
                                      ((uint)(i2 & 0x0003f000) >> 4) |
                                       (uint)(i2 & 0x0000003f));
            }

            return newKey;
        }