Thursday, March 22, 2012

[C#] CFB (Cipher Feedback)

          Hello, Reader ^^! Back again with source code. This time is is CFB (Cipher Feedback) which is made using C# programming language. This one, like CBC, also encrypts block per block from previous blocks. The first block uses Initialization Vector. The IV (and the next xor-ed plaintext and Encryption Block), will be encrypted into Encryption Block. After that, it will xor-ed with plaintext which will be the ciphertext. A mistake just a bit can lead mistake also in the encryption and decryption. The Encryption Block used in this example is the simple XOR. You can define your own Encryption Block like doing shift left, shift right, etc. Now, let me demonstrate a bit:

plain text (in bit) : 0101111111010101
key : 10101
IV generated 10001
Encryption Block = a xor b

Now, splitting them into 5 blocks (based on key's length): 01011|11111|01010|1
The last part length is not 5, so let's padding it with 0 bits : 10000

IV(only 1st block), then from the Fifth row 10001 10001 11011 01110 
Key01011 10101 11111 00000 
Encryption Block (a xor b; a is first row, b is key) 11010001000010001110
Plaintext (in bits)
01011 11111 01010 10000
Xor-ed (Plaintext with third row)  

The result of encryption is 10001110110111011111. If you see at the 3rd column, at the 2nd row, you will see the value is taken from 2nd column, 5th row. Yup, that's why it is chaining.

Okay, that's all I can say. Thank you for reading ^^!

Download Source Code
- Dropbox
- Dropbox (Repository)
- GitHub
GitHub (Repository)