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[0] = IV

   for i = 0 to nBlocks-1
     cipher[i+1] = (encrypt key plainText[i]) XOR cipher[i]


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]


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]

| cite | improve this answer | |
  • $\begingroup$ By example I mean a step by step manual example to show how cbc or ecb is performed. It's a practice question sort of thing for exam $\endgroup$ – x89 May 27 at 23:03
  • $\begingroup$ @x89 Pseudocode now added $\endgroup$ – Koenig Lear May 28 at 4:50
  • $\begingroup$ Still looking for an example on how to use it $\endgroup$ – x89 May 28 at 9:33
  • $\begingroup$ I can't figure out how to use encrypt key etc $\endgroup$ – x89 May 28 at 9:44
  • $\begingroup$ @x89 encrypt key depends from your cypher. AES for example is very complex to describe. A naive encrypt function is xor : encrypt key data = data xor key and decrypt key cipher = data xor key $\endgroup$ – Koenig Lear May 28 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.