Thursday, March 22, 2012

[C#] CBC (Cipher-Block Chaining)

          Hello, Reader ^^! Back again with source code. This time is is CBC (Cipher-Block Chaining) which is made using C# programming language. This one, uses encryption per block which came from the previous block. This way, the encryption becomes stronger, not only that, with Initialization Vector which is generated random, it made encryption more unique even with the same key. The IV can be kept or not, because when decryption, it won't effect the other block not like when enciphering. 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





Plaintext(in bits)01011111110101010000
IV(only 1st block), then from the Encryption Block 01011 10101 11111 00000 
Xor-ed (Plaintext with second row)00000010101010110000 
Key1010110101 10101 10101 
Encryption Block (a xor b; a is xor-ed bits, b is key)10101111110000000101


The result of encryption is 10101111110000000101. 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.

One more thing, it also can encrypt and decrypt file like the other block cipher mode :D (I forgot to mention it with toher block cipher mode). Okay, that's all I can say. Thank you for reading ^^!



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





No comments:

Post a Comment