コード例 #1
0
ファイル: DESCrptography.cs プロジェクト: uvbs/MyProjects
            public void Set(BLOCK8BYTE Source)
            {

                // Copy source data to this
                this.Set(Source.m_data, 0);

            }
コード例 #2
0
 internal KeySet()
 {
     // Create array
     _array = new BLOCK8BYTE[KEY_COUNT];
     for (int i1 = 0; i1 < KEY_COUNT; i1++)
         _array[i1] = new BLOCK8BYTE();
 }
コード例 #3
0
ファイル: DESCrptography.cs プロジェクト: uvbs/MyProjects
            public void Xor(BLOCK8BYTE A, BLOCK8BYTE B)
            {

                // Set byte to A ^ B
                for (int iOffset = 0; iOffset < BYTE_LENGTH; iOffset++)
                    m_data[iOffset] = Convert.ToByte(A.m_data[iOffset] ^ B.m_data[iOffset]);

            }
コード例 #4
0
 public void Xor(BLOCK8BYTE A, BLOCK8BYTE B)
 {
     // Set byte to A ^ B
     for (int iOffset = 0; iOffset < BYTE_LENGTH; iOffset++)
     {
         m_data[iOffset] = Convert.ToByte(A.m_data[iOffset] ^ B.m_data[iOffset]);
     }
 }
コード例 #5
0
 internal WorkingSet()
 {
     // Build the arrays
     for (int i1 = 0; i1 < 17; i1++)
     {
         Ln[i1] = new BLOCK8BYTE();
         Rn[i1] = new BLOCK8BYTE();
     }
 }
コード例 #6
0
ファイル: WorkingSet.cs プロジェクト: 284247028/MvvmCross
 internal WorkingSet()
 {
     // Build the arrays
     for (int i1 = 0; i1 < 17; i1++)
     {
         Ln[i1] = new BLOCK8BYTE();
         Rn[i1] = new BLOCK8BYTE();
     }
 }
コード例 #7
0
ファイル: KeySet.cs プロジェクト: hasnain2663/MvvmCross-1
 internal KeySet()
 {
     // Create array
     _array = new BLOCK8BYTE[KEY_COUNT];
     for (int i1 = 0; i1 < KEY_COUNT; i1++)
     {
         _array[i1] = new BLOCK8BYTE();
     }
 }
コード例 #8
0
            /////////////////////////////////////////////////////////
            // Construction

            internal WORKING_SET()
            {
                // Build the arrays
                for (int i1 = 0; i1 < 17; i1++)
                {
                    Ln[i1] = new BLOCK8BYTE();
                    Rn[i1] = new BLOCK8BYTE();
                }
            }
コード例 #9
0
            /////////////////////////////////////////////////////////
            // Construction

            internal KEY_SET()
            {
                // Create array
                m_array = new BLOCK8BYTE[KEY_COUNT];
                for (int i1 = 0; i1 < KEY_COUNT; i1++)
                {
                    m_array[i1] = new BLOCK8BYTE();
                }
            }
コード例 #10
0
            public void ShiftLeftWrapped(BLOCK8BYTE S, int iBitShift)
            {
                // this shift is only applied to the first 32 bits, and parity bit is ignored

                // Declaration of local variables
                int  iByteOffset = 0;
                bool bBit        = false;

                // Copy byte and shift regardless
                for (iByteOffset = 0; iByteOffset < 4; iByteOffset++)
                {
                    m_data[iByteOffset] = Convert.ToByte((S.m_data[iByteOffset] << iBitShift) & 0xFF);
                }

                // if shifting by 1...
                if (iBitShift == 1)
                {
                    // repair bits on right of BYTE
                    for (iByteOffset = 0; iByteOffset < 3; iByteOffset++)
                    {
                        // get repairing bit offsets
                        bBit = S.GetBit(iByteOffset + 1, 7);
                        this.SetBit(iByteOffset, 1, bBit);
                    }

                    // wrap around the final bit
                    this.SetBit(3, 1, S.GetBit(0, 7));
                }
                else if (iBitShift == 2)
                {
                    // repair bits on right of BYTE
                    for (iByteOffset = 0; iByteOffset < 3; iByteOffset++)
                    {
                        // get repairing bit offsets
                        bBit = S.GetBit(iByteOffset + 1, 7);
                        this.SetBit(iByteOffset, 2, bBit);
                        bBit = S.GetBit(iByteOffset + 1, 6);
                        this.SetBit(iByteOffset, 1, bBit);
                    }

                    // wrap around the final bit
                    this.SetBit(3, 2, S.GetBit(0, 7));
                    this.SetBit(3, 1, S.GetBit(0, 6));
                }
#if DEBUG
                else
                {
                    Debug.Assert(false);
                }
#endif // #if DEBUG
            }
コード例 #11
0
ファイル: DESCrptography.cs プロジェクト: uvbs/MyProjects
            public void ShiftLeftWrapped(BLOCK8BYTE S, int iBitShift)
            {

                // this shift is only applied to the first 32 bits, and parity bit is ignored

                // Declaration of local variables
                int iByteOffset = 0;
                bool bBit = false;

                // Copy byte and shift regardless
                for (iByteOffset = 0; iByteOffset < 4; iByteOffset++)
                    m_data[iByteOffset] = Convert.ToByte((S.m_data[iByteOffset] << iBitShift) & 0xFF);

                // if shifting by 1...
                if (iBitShift == 1)
                {

                    // repair bits on right of BYTE
                    for (iByteOffset = 0; iByteOffset < 3; iByteOffset++)
                    {

                        // get repairing bit offsets
                        bBit = S.GetBit(iByteOffset + 1, 7);
                        this.SetBit(iByteOffset, 1, bBit);

                    }

                    // wrap around the final bit
                    this.SetBit(3, 1, S.GetBit(0, 7));

                }
                else if (iBitShift == 2)
                {

                    // repair bits on right of BYTE
                    for (iByteOffset = 0; iByteOffset < 3; iByteOffset++)
                    {

                        // get repairing bit offsets
                        bBit = S.GetBit(iByteOffset + 1, 7);
                        this.SetBit(iByteOffset, 2, bBit);
                        bBit = S.GetBit(iByteOffset + 1, 6);
                        this.SetBit(iByteOffset, 1, bBit);

                    }

                    // wrap around the final bit
                    this.SetBit(3, 2, S.GetBit(0, 7));
                    this.SetBit(3, 1, S.GetBit(0, 6));

                }
#if DEBUG
                else
                    Debug.Assert(false);
#endif // #if DEBUG

            }
コード例 #12
0
ファイル: DESCrptography.cs プロジェクト: uvbs/MyProjects
        private static KEY_SET _expandKey(byte[] Key, int iOffset)
        {

            //
            // Expand an 8 byte DES key into a set of permuted keys
            //

            // Declare return variable
            KEY_SET Ftmp = new KEY_SET();

            // Declaration of local variables
            int iTableOffset, iArrayOffset, iPermOffset, iByteOffset, iBitOffset;
            bool bBit;

            // Put key into an 8-bit block
            BLOCK8BYTE K = new BLOCK8BYTE();
            K.Set(Key, iOffset);

            // Permutate Kp with PC1
            BLOCK8BYTE Kp = new BLOCK8BYTE();
            for (iArrayOffset = 0; iArrayOffset < bytePC1.Length; iArrayOffset++)
            {

                // Get permute offset
                iPermOffset = bytePC1[iArrayOffset];
                iPermOffset--;

                // Get and set bit
                Kp.SetBit(
                    _bitAddressToByteOffset(iArrayOffset, 7),
                    _bitAddressToBitOffset(iArrayOffset, 7),
                    K.GetBit(
                        _bitAddressToByteOffset(iPermOffset, 8),
                        _bitAddressToBitOffset(iPermOffset, 8)
                    )
                );

            }

            // Create 17 blocks of C and D from Kp
            BLOCK8BYTE[] KpCn = new BLOCK8BYTE[17];
            BLOCK8BYTE[] KpDn = new BLOCK8BYTE[17];
            for (iArrayOffset = 0; iArrayOffset < 17; iArrayOffset++)
            {
                KpCn[iArrayOffset] = new BLOCK8BYTE();
                KpDn[iArrayOffset] = new BLOCK8BYTE();
            }
            for (iArrayOffset = 0; iArrayOffset < 32; iArrayOffset++)
            {

                // Set bit in KpCn
                iByteOffset = _bitAddressToByteOffset(iArrayOffset, 8);
                iBitOffset = _bitAddressToBitOffset(iArrayOffset, 8);
                bBit = Kp.GetBit(iByteOffset, iBitOffset);
                KpCn[0].SetBit(iByteOffset, iBitOffset, bBit);

                // Set bit in KpDn
                bBit = Kp.GetBit(iByteOffset + 4, iBitOffset);
                KpDn[0].SetBit(iByteOffset, iBitOffset, bBit);

            }
            for (iArrayOffset = 1; iArrayOffset < 17; iArrayOffset++)
            {

                // Shift left wrapped
                KpCn[iArrayOffset].ShiftLeftWrapped(KpCn[iArrayOffset - 1], byteShifts[iArrayOffset - 1]);
                KpDn[iArrayOffset].ShiftLeftWrapped(KpDn[iArrayOffset - 1], byteShifts[iArrayOffset - 1]);

            }

            // Create 17 keys Kn
            for (iArrayOffset = 0; iArrayOffset < 17; iArrayOffset++)
            {

                // Loop through the bits
                for (iTableOffset = 0; iTableOffset < 48; iTableOffset++)
                {

                    // Get address if bit
                    iPermOffset = bytePC2[iTableOffset];
                    iPermOffset--;

                    // Convert to byte and bit offsets
                    iByteOffset = _bitAddressToByteOffset(iPermOffset, 7);
                    iBitOffset = _bitAddressToBitOffset(iPermOffset, 7);

                    // Get bit
                    if (iByteOffset < 4)
                        bBit = KpCn[iArrayOffset].GetBit(iByteOffset, iBitOffset);
                    else
                        bBit = KpDn[iArrayOffset].GetBit(iByteOffset - 4, iBitOffset);

                    // Set bit
                    iByteOffset = _bitAddressToByteOffset(iTableOffset, 6);
                    iBitOffset = _bitAddressToBitOffset(iTableOffset, 6);
                    Ftmp.GetAt(iArrayOffset).SetBit(iByteOffset, iBitOffset, bBit);

                }

            }

            // Return variable
            return Ftmp;

        }
コード例 #13
0
ファイル: DESCrptography.cs プロジェクト: uvbs/MyProjects
            /////////////////////////////////////////////////////////
            // Construction

            internal WORKING_SET()
            {

                // Build the arrays
                for (int i1 = 0; i1 < 17; i1++)
                {
                    Ln[i1] = new BLOCK8BYTE();
                    Rn[i1] = new BLOCK8BYTE();
                }

            }
コード例 #14
0
ファイル: DESCrptography.cs プロジェクト: uvbs/MyProjects
            /////////////////////////////////////////////////////////
            // Construction

            internal KEY_SET()
            {

                // Create array
                m_array = new BLOCK8BYTE[KEY_COUNT];
                for (int i1 = 0; i1 < KEY_COUNT; i1++)
                    m_array[i1] = new BLOCK8BYTE();

            }
コード例 #15
0
        private static KEY_SET _expandKey(byte[] Key, int iOffset)
        {
            //
            // Expand an 8 byte DES key into a set of permuted keys
            //

            // Declare return variable
            KEY_SET Ftmp = new KEY_SET();

            // Declaration of local variables
            int  iTableOffset, iArrayOffset, iPermOffset, iByteOffset, iBitOffset;
            bool bBit;

            // Put key into an 8-bit block
            BLOCK8BYTE K = new BLOCK8BYTE();

            K.Set(Key, iOffset);

            // Permutate Kp with PC1
            BLOCK8BYTE Kp = new BLOCK8BYTE();

            for (iArrayOffset = 0; iArrayOffset < bytePC1.Length; iArrayOffset++)
            {
                // Get permute offset
                iPermOffset = bytePC1[iArrayOffset];
                iPermOffset--;

                // Get and set bit
                Kp.SetBit(
                    _bitAddressToByteOffset(iArrayOffset, 7),
                    _bitAddressToBitOffset(iArrayOffset, 7),
                    K.GetBit(
                        _bitAddressToByteOffset(iPermOffset, 8),
                        _bitAddressToBitOffset(iPermOffset, 8)
                        )
                    );
            }

            // Create 17 blocks of C and D from Kp
            BLOCK8BYTE[] KpCn = new BLOCK8BYTE[17];
            BLOCK8BYTE[] KpDn = new BLOCK8BYTE[17];
            for (iArrayOffset = 0; iArrayOffset < 17; iArrayOffset++)
            {
                KpCn[iArrayOffset] = new BLOCK8BYTE();
                KpDn[iArrayOffset] = new BLOCK8BYTE();
            }
            for (iArrayOffset = 0; iArrayOffset < 32; iArrayOffset++)
            {
                // Set bit in KpCn
                iByteOffset = _bitAddressToByteOffset(iArrayOffset, 8);
                iBitOffset  = _bitAddressToBitOffset(iArrayOffset, 8);
                bBit        = Kp.GetBit(iByteOffset, iBitOffset);
                KpCn[0].SetBit(iByteOffset, iBitOffset, bBit);

                // Set bit in KpDn
                bBit = Kp.GetBit(iByteOffset + 4, iBitOffset);
                KpDn[0].SetBit(iByteOffset, iBitOffset, bBit);
            }
            for (iArrayOffset = 1; iArrayOffset < 17; iArrayOffset++)
            {
                // Shift left wrapped
                KpCn[iArrayOffset].ShiftLeftWrapped(KpCn[iArrayOffset - 1], byteShifts[iArrayOffset - 1]);
                KpDn[iArrayOffset].ShiftLeftWrapped(KpDn[iArrayOffset - 1], byteShifts[iArrayOffset - 1]);
            }

            // Create 17 keys Kn
            for (iArrayOffset = 0; iArrayOffset < 17; iArrayOffset++)
            {
                // Loop through the bits
                for (iTableOffset = 0; iTableOffset < 48; iTableOffset++)
                {
                    // Get address if bit
                    iPermOffset = bytePC2[iTableOffset];
                    iPermOffset--;

                    // Convert to byte and bit offsets
                    iByteOffset = _bitAddressToByteOffset(iPermOffset, 7);
                    iBitOffset  = _bitAddressToBitOffset(iPermOffset, 7);

                    // Get bit
                    if (iByteOffset < 4)
                    {
                        bBit = KpCn[iArrayOffset].GetBit(iByteOffset, iBitOffset);
                    }
                    else
                    {
                        bBit = KpDn[iArrayOffset].GetBit(iByteOffset - 4, iBitOffset);
                    }

                    // Set bit
                    iByteOffset = _bitAddressToByteOffset(iTableOffset, 6);
                    iBitOffset  = _bitAddressToBitOffset(iTableOffset, 6);
                    Ftmp.GetAt(iArrayOffset).SetBit(iByteOffset, iBitOffset, bBit);
                }
            }

            // Return variable
            return(Ftmp);
        }
コード例 #16
0
 public void Set(BLOCK8BYTE Source)
 {
     // Copy source data to this
     this.Set(Source.m_data, 0);
 }