I am learning about block ciphers and while I understand the concept of Electronic Codeblock mode and cipher block chaining, I could not find any relevant practical examples online. Can someone provide a short example of a scenario where we convert plain text into cipher text using ecb and cbc (with initialization vector and keys).
A common scenario is browsing this page e.g. TLS Transport Layer Security uses CBC for example AES among others to encrypt the content between Stack exchange servers and your browser.
CBC Pseudocode for Encryption
cbc key IV plainText nBlocks = cipher = IV for i = 0 to nBlocks-1 cipher[i+1] = (encrypt key plainText[i]) XOR cipher[i] cipher
CBC Pseudocode for Decryption
cbc' key cipher nBlocks = for i = nBlocks-1 downto 1 plainText[i-1] = (decrypt key cipher[i]) XOR cypher[i-1] plainText
A naive encrypt function is
encrypt key data = data xor key decrypt key data = data xor key
you could use this functions in something like this:
let a = [1,2,3] let iv = 81 let key = 365 let cipher = cbc key iv a 3
and if you do
cbc' cipher key 4
you should get back [1,2,3]