Question

Ok, before you guys reprimand me : I am aware this is a horrible code and super weak cipher. I just trying to find out if the following qualifies to be a block cipher ( even a very rudimentary and weak one )

int main(){
   int mac = 123;
   int key = 789;

   int enc = mac^key;
   printf("encrypted text  =  %d\n",enc);

   int plain = enc^key;
   printf("decrypted text = %d\n",plain);

   return 0;
}

Here is the output :

encrypted text  =  878
decrypted text = 123
Was it helpful?

Solution

There are certain generalities that have to be followed in order to create a block cipher. The code you have shown is technically not a block cipher. Generalities such as:

  • In a block cipher the message is broken into blocks, each of which is then encrypted (ie like a substitution on very big characters - 64-bits or more)
  • A block cipher consists of two paired algorithms, one for encryption, E, and the other for decryption, E−1. Both algorithms accept two inputs: an input block of size n bits and a key of size k bits, yielding an n-bit output block. For any one fixed key, decryption is the inverse function of encryption.

Encryption in block cipher mode (ECB, CBC) uses a specific flow:

  • The first thing that a block cipher must do is break the plaintext into equally-sized blocks, usually 8 bytes, for instance the ASCII encoding of imablock.
  • Encrypt the plaintext using a cipher.
  • Decrypt the message.

The choice of cipher is implementation dependent.

The point being, while you may have followed the flow for Encryption-Decryption, you program doesn't satisfy the generalities of block ciphers. You need to break your message into blocks to implement a symmetric cipher.

What you have implemented, is simple encryption and not a block cipher.

There are so many references:

Hope it helps. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top