System.Security.Cryptography.DESTransform.SetKey C# (CSharp) Метод

SetKey() приватный Метод

private SetKey ( byte key ) : void
key byte
Результат void
		internal void SetKey (byte[] key)
		{
			// NOTE: see Fig. 3, Key schedule calculation, at page 20.
			Array.Clear (keySchedule, 0, keySchedule.Length);
	
			int keyBitSize = PC1.Length;
	
			byte[] keyPC1 = new byte [keyBitSize]; // PC1-permuted key
			byte[] keyRot = new byte [keyBitSize]; // PC1 & rotated
	
			int indx = 0;
	
			foreach (byte bitPos in PC1) {
				keyPC1 [indx++] = (byte)((key [(int)bitPos >> 3] >> (7 ^ (bitPos & 7))) & 1);
			}
	
			int j;
			for (int i = 0; i < KEY_BYTE_SIZE*2; i++) {
				int b = keyBitSize >> 1;
	
				for (j = 0; j < b; j++) {
					int s = j + (int) leftRotTotal [i];
					keyRot [j] = keyPC1 [s < b ? s : s - b];
				}
	
				for (j = b; j < keyBitSize; j++) {
					int s = j + (int) leftRotTotal [i];
					keyRot [j] = keyPC1 [s < keyBitSize ? s : s - b];
				}
	
				int keyOffs = i * KEY_BYTE_SIZE;
	
				j = 0;
				foreach (byte bitPos in PC2) {
					if (keyRot [(int)bitPos] != 0) {
						keySchedule [keyOffs + (j/6)] |= (byte) (0x80 >> ((j % 6) + 2));
					}
					j++;
				}
			}
		}