One of the important ingredients in modern cryptographic systems is the ability to break messages into smaller blocks, each one being independently encrypted. In conjunction with the other components in a cryptosystem, this makes it harder to decrypt the message as a whole without the key. These are known as block ciphers.
Electronic Code Book (ECB)
ECB is the most straightforward example of block cipher I came across. Basically a plaintext message is converted into binary ASCII code with four digits to each character. This is useful because we can now have a message divided into blocks of four digits and each block can be encrypted separately.
It works by taking an arbitrary value for the key (k), the plaintext block (p), and using those to generate a cipher block (c). The key (k) is XORed with a plaintext block (p), and the resulting block is shifted one place.
p = 1010
k = 1011
k XOR p = 0001
c = 0010
There are major weaknesses with using ECB. The main one in this case is a plaintext block will always translate into the same ciphertext block, so each character would still have its corresponding ciphertext. The end result on its own is little better than a substitution cipher.
We overcome this by using a value that’s different for each block when generating the ciphertext, so it isn’t determined solely by the key and a Boolean function. Each character of plaintext should then translate into a different ciphertext character each time it occurs, and this makes statistical analysis much harder.
Cipher Block Chaining (CBC)
So called because each block of ciphertext is largely determined by the previous one. For example, if we have a set of blocks c1, c2, c3, and c4, the value of c4 is determined partly by c3.
This can be done by XORing c1 with the corresponding plaintext p2, and then XORing the result with the key (k) before shifting the digits one place.
1. XOR plaintext block with previous ciphertext block.
2. XOR block with k
3. Shift block one digit to the left
p2 = 0010
c1 = 0010
p2 XOR c1 = 0000
k = 1011
(p2 XOR c1) XOR k = 1011
c2 = 0111