0

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
sukhvir
  • 5,265
  • 6
  • 41
  • 43
  • 1
    If the key consist of perfectly random bits and is not reused, then this is actually an implementation of a [one time pad](http://en.wikipedia.org/wiki/One-time_pad), not a block cipher. – Maarten Bodewes Oct 01 '13 at 19:39
  • If this were an algorithm rather than an example it might be a block cipher. But it might just as well be a one time pad, or something else. – President James K. Polk Oct 02 '13 at 16:33
  • how about if i were split each digit of the mac and and then do the same as above. It would be the same output, However now I am breaking them message into "blocks" of single digits and doing XOR and then recombining them at the other end – sukhvir Oct 02 '13 at 23:55
  • IMO it is a block cipher. A really bad one, but one none the less. – CodesInChaos Oct 16 '13 at 11:47

1 Answers1

5

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. :)

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
user2339071
  • 4,254
  • 1
  • 27
  • 46
  • thanks a lot .. this settles an argument I have been having with my friend over this code – sukhvir Oct 01 '13 at 05:36
  • Hahaha. Friends huh.. :P .. Glad to help. :) – user2339071 Oct 01 '13 at 05:37
  • +1 removed some code blocks that were used for highlighting though, and added some minor clarifications. To be precise, a block cipher can only encrypt/decrypt a single block, the division in blocks of plain text is purely part of a [block cipher mode of operation](http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation). – Maarten Bodewes Oct 01 '13 at 19:33