System.Security.Cryptography.DESTransform.ProcessBlock C# (CSharp) Method

ProcessBlock() public method

public ProcessBlock ( byte input, byte output ) : void
input byte
output byte
return void
		public void ProcessBlock (byte[] input, byte[] output) 
		{
			Buffer.BlockCopy (input, 0, dwordBuff, 0, BLOCK_BYTE_SIZE);
	
			if (encrypt) {
				uint d0 = dwordBuff [0];
				uint d1 = dwordBuff [1];
	
				// 16 rounds
				d0 ^= CipherFunct (d1,  0);
				d1 ^= CipherFunct (d0,  1);
				d0 ^= CipherFunct (d1,  2);
				d1 ^= CipherFunct (d0,  3);
				d0 ^= CipherFunct (d1,  4);
				d1 ^= CipherFunct (d0,  5);
				d0 ^= CipherFunct (d1,  6);
				d1 ^= CipherFunct (d0,  7);
				d0 ^= CipherFunct (d1,  8);
				d1 ^= CipherFunct (d0,  9);
				d0 ^= CipherFunct (d1, 10);
				d1 ^= CipherFunct (d0, 11);
				d0 ^= CipherFunct (d1, 12);
				d1 ^= CipherFunct (d0, 13);
				d0 ^= CipherFunct (d1, 14);
				d1 ^= CipherFunct (d0, 15);
	
				dwordBuff [0] = d1;
				dwordBuff [1] = d0;
			}
			else {
				uint d1 = dwordBuff [0];
				uint d0 = dwordBuff [1];
	
				// 16 rounds in reverse order
				d1 ^= CipherFunct (d0, 15);
				d0 ^= CipherFunct (d1, 14);
				d1 ^= CipherFunct (d0, 13);
				d0 ^= CipherFunct (d1, 12);
				d1 ^= CipherFunct (d0, 11);
				d0 ^= CipherFunct (d1, 10);
				d1 ^= CipherFunct (d0,  9);
				d0 ^= CipherFunct (d1,  8);
				d1 ^= CipherFunct (d0,  7);
				d0 ^= CipherFunct (d1,  6);
				d1 ^= CipherFunct (d0,  5);
				d0 ^= CipherFunct (d1,  4);
				d1 ^= CipherFunct (d0,  3);
				d0 ^= CipherFunct (d1,  2);
				d1 ^= CipherFunct (d0,  1);
				d0 ^= CipherFunct (d1,  0);
	
				dwordBuff [0] = d0;
				dwordBuff [1] = d1;
			}
	
			Buffer.BlockCopy (dwordBuff, 0, output, 0, BLOCK_BYTE_SIZE);
		}
	

Usage Example

Example #1
0
 // note: this method is garanteed to be called with a valid blocksize
 // for both input and output
 protected override void ECB(byte[] input, byte[] output)
 {
     DESTransform.Permutation(input, output, DESTransform.ipTab, false);
     if (encrypt)
     {
         E1.ProcessBlock(output, output);
         D2.ProcessBlock(output, output);
         E3.ProcessBlock(output, output);
     }
     else
     {
         D1.ProcessBlock(output, output);
         E2.ProcessBlock(output, output);
         D3.ProcessBlock(output, output);
     }
     DESTransform.Permutation(output, output, DESTransform.fpTab, true);
 }