.

Saturday, March 17, 2012

[Ruby] CBC (Cipher-Block Chaining)

          Hello, Reader ^^! Back again with source code. This time is is CBC (Cipher-Block Chaining) which is made using Ruby 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. Now, let me demonstrate a bit:

plain text (in bit) : 0101111111010101
key : 10101
IV generated 10001

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
Key per block 10101 10101 10101 10101 
IV(only 1st block), then with the ciphered block0101110101 11111 00000 
Xor-ed10101111110000000101


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

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







No comments:

Post a Comment